Is it ok to assume /tmp folder writable by PHP/Apache on any unix system? I'm making a script and want to save cache in the tmp folder and want to know whether that can cause problems.
+3
A:
It should be OK. /tmp
is made for everyone to use. But be careful, it also means that anyone can read your files if you don't set specific permissions!
If you are unsure, make your installation script check the /tmp
folder and make it possible for the user to configure another temp location. This is probably the best bet anyway because different users have different needs. Consider for example a user with load-balanced servers; she might want to use a folder which is shared between all her hosts.
Emil Vikström
2010-10-18 09:47:27
+1! `/tmp` has 777 permissions by default. You should be able to use it in most cases.
elusive
2010-10-18 09:48:35
A:
You can not rely on /tmp folder as in some variations of linux, it is auto cleaned after some time, it would be best for your application to have a local tmp folder inside the app, which you manage yourself.
Sabeen Malik
2010-10-18 09:47:50
On those distributions, the cleaning script will only remove old files (usually between a few hours and a few days, depending on distro). It would be bad to the system if you cleaned EVERYTHING from /tmp, even files which are only a few seconds old.
Emil Vikström
2010-10-18 09:51:59
I think since I'm going to store cache in that folder, the worst outcome I may encounter is deleted cache files which isn't a problem by definition
roddik
2010-10-18 09:55:50
@Emil Vikström .. yes that is true however my point is still the same , that you may want to cache some things for quite some time and incase of tmp folder, you are not in control of that.
Sabeen Malik
2010-10-18 09:57:04
Also if i remember correctly in most distros the tmp folder is cleared when you reboot, that would be ideal for most.
Sabeen Malik
2010-10-18 10:00:13