简体   繁体   中英

What is the difference between sys_temp_dir and upload_tmp_dir in PHP?

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.

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

; sys_temp_dir = "/tmp"
; upload_tmp_dir =

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM