/tmp is getting full. Any way to clean it with cron?

ozgurerdogan

Verified User
Joined
Apr 20, 2008
Messages
352
/tmp is getting full very quick with some vps. Any way to clean it with cron? Or should I consider it update to a larger space.Currently 2 GB.
 
What type of files are in /tmp. Is it php session files? If you have a lot of ram you can run tmp in memory instead of physical disk.
 
Yes they are all php sersions. But How do they take space as they are seen 1 Kb. I mean /tmp partition is shows as 1 gb full but sessions files are not that much. Is it because as they deleted, tmp partition must be zerofilled?
It is only one site on server with high traffic. It has 2 gb of ram. Can I empty them?
 
Last edited:
If you have a lot of space in /home you should be able to use /home/tmp instead of /tmp. You would just have to change sessions.save_path in php.ini and restart the web server. Those tiny 1kb files can add up fast if there is a ton of them. Deleting them would just cause sessions to be destroyed for people on the website. Moving the php sessions is the best idea. Make sure /home/tmp exists before setting it. I am pretty sure it does exist by default.
 
The tmp gets full because the operating system allocates disk space for files in (usually) 4KB blocks, even if you have files of 1 byte each.
Check the timestamp of the session files. Usually you can delete session files older than, say 12 hours. Depending on the usage of the sessions you can in-/decrease the number of hours to keep them.
Run 'tmpwatch' from a cronjob every hour/minute/day (whatever is best for your situation) to clean up old sessions.
 
Consider also the temp files which are randomly created from mysql process. If this is the case change the default directory in my.cnf
 
If all those temporary files are being deleted after a while, I guess all I need to do is move them to a larger partition. Am i right?
 
I can help you
you should first determine why /tmp is quickly full.
for one reason , when you opencart many session file create on /tmp or when mysql execute a large sql command too.
send server information , i fix your problem.
 
If all those temporary files are being deleted after a while, I guess all I need to do is move them to a larger partition. Am i right?

That might happen so that 4Gb, 8Gb, etc... would end sooner or later. Or even all the disk will be used to store temp files. So you probably need to understand why there are so many session files. Is your site under spambot attack? Bruteforce attack? Other malicious activity? Or all the sessions are opened by regular and legitimate users?
 
Site has very high traffic and I guess thats why. They are seem to be session file for php.
 
Usually you only need to start a session for users that are logged in or if you present customized output to some user(groups).
An often made mistake is to start sessions even if the user doesn't really need a session. With high traffic sites you'll see many sessionfiles in /tmp with a 0 size. These are all wasted space.

Some point already mentioned is mysql. Mysql creates it's temporary files (if they cannot be created in RAM) on disk in the /tmp dir. Sometimes these files can get pretty big, but they are deleted as soon as the query is finished.
For extra performance (and if you have ram enough) you might want to move the mysql tmp files to a ramdisk.
 
Back
Top