Reputation: 2005
I have problem on my web server.
I noticed that often big files are created in /tmp directory. Files are like /tmp/phpUNIQUECODE But these are not uploads. Because in my php.ini settings configuration is
upload_tmp_dir = /backup/tmp
upload_max_filesize = 300M
post_max_size = 300M
I found that files in /tmp are written by PHP process while downloading file (PHP process reads a file from TCP socket and writes to output).
I read some PHP manuals and i see that tehre is PHP function tmpfile(). It creates temp file in /tmp folder (even if upload_tmp_dir is different ). But this function is not used in my code. In my code nothing is saved to the disk.
What can this be? What other PHP extensions can create temporary file in /tmp folder?
Thanks.
Update 1. IN my download function i use ob_start and ob_flush functions. ob_flush is calles after every 4kb of data are posted to a browser.
Can this problem be related to ob_* functions?
Update 2. I found that on other server where i execute the same PHP code to download files there is no temp files in /tmp folder. So this must be related to php.ini settings or apache settings. Also i found that temp files are copy of files is being downloaded. And when download is complete then temp file is removed from /tmp folder.
Update 3. I isolated this problem. I found thsi is not problem of downloading. This is problem of reading files with PHP HTTP wrapper. My files are stored on amazon s3. I open socket to download file with
$fh=fopen('http://s3.amazonaws.com/.....');
then i read the file and send to user browser. I did some tests and found that if i real file from local source then all is fine. Temp files are not created. Also i tested with other wrappers - ftp and also some custom wrappers (for example, custom wrapper for dropbox). And all is fine.
So the problem is only for php http wrapper and only on one my server (same code on other servers is fine).
This simple code demonstrates my problem:
$filepath='http://bucket.s3.amazonaws.com/.....';
$_fp=fopen($filepath,'r');
if ($_fp) {
$i=1;
$total=0;
while (!feof($_fp)) {
$tmpbuf=fread($_fp, 4096);
$total+=strlen($tmpbuf);//this is done only to make downloading slower
if($total>=$i*4194304){
$i++;
sleep(1);//just to make downloading slower
}
}
fclose($_fp);
}
If i replace first line to
$filepath='/path/to/local/file';
Then all is fine. Temp file is not created in /tmp folder
Any ideas about this strange problem?
Upvotes: 4
Views: 4233
Reputation: 3331
as cryptic said it sounds like php sessions, in your php.ini check to see the value of
session.save_path
additional----
okay so probably not session files, I have reread your OP and your extra comments and if the file is created by a script that downloads data, and are cleaned up when the script completes what is the problem?
Also I will point out that the settings upload_tmp_dir is for uploading files over HTTP (according to the comments in default php.ini) so presumably nothing to do with downloading. What code are you using to download? Are there settings for that command?
updated
Since the /tmp files match the size and timings of the downloaded files, then It does look like that is how the operating system stores the files while it is collating the data. I doubt it is anything to worry about, especially if the files are routinely a couple of gig. it is likely that it spools to disc to preserve system RAM
updated 2
Maybe me referring to it as the OS isn't quite right, maybe it is somewhere in the guts of PHP that chooses the name / creates the tmp file. The bottom line as I see it - based on everything you have said - is that there is no problem here, that is just how PHP works.
The other server might be set to write tmp files elsewhere, but without you actually supplying the code snippet you are using for inspection, I don't see how anyone can help you with more detail.
What problem are these tmp files causing you?
Upvotes: 2