1

Or rather, is there anyway to set the system temp directory (NOT the upload temp directory) in PHP?

When I run

echo sys_get_temp_dir();

I get /tmp. When I run

ini_get('upload_tmp_dir');

I get the directory that I specified in my php.ini file. Is there anyway to change what PHP uses for the sys temp dir?

I keep having random files show up in my /tmp directory. These are prefixed by "php" and then have a series of random numbers and letters. From what I can tell, these are probably being generated by PHP tmpfile or tempnam. httpd is the process that is using them when they are created. They are massive files that fill up my entire /tmp partition and take my server down. I can't figure out where they are coming from. I could increase the /tmp partition size from 500MB to 2GB but I'd rather avoid that if I can.

I don't understand where the sys_get_temp_dir() is pulling /tmp from. Everything I search for just tells me to change the upload_tmp_dir in .ini but these are two separate things.

Hexaholic
  • 3,299
  • 7
  • 30
  • 39
Commander Keen
  • 55
  • 1
  • 2
  • 10

2 Answers2

2

in php.ini you should have to diferent settings for this:

; sys_temp_dir = "/tmp"
; upload_tmp_dir =
Puggan Se
  • 5,738
  • 2
  • 22
  • 48
-2

The files in /tmp are your session files. PHP writes those to disk by default. You can see this if you run session_save_path

echo session_save_path();

You can then run that function again to change the path but it sounds like you have too many sessions.

You can help to avoid this by storing your sessions inside your database instead of on disk. You can also have PHP do more session cleanups.

Community
  • 1
  • 1
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • 1
    I wouldn't say "fix". I would say "change". Writing sessions to the disk is not an error that needs to be fixed. – kainaw May 07 '15 at 19:14
  • The output of echo session_save_path() is /var/lib/php/session. The main issue isn't the number of these files, but the size. It doesn't happen often but when it does, it's one single file that is over 400MB and fills the directory. The file in question is named "phpa4subv." Everytime this happens the file is named php--something. It's hard to get any info since its randomly generated. No file extension either. It sounded like something tempnam/tmpfile would create. – Commander Keen May 07 '15 at 20:04