What PHP extensions write temp files to to /tmp folder?
<p>I have problem on my web server.</p>

<p>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</p>

<pre><code>upload_tmp_dir = /backup/tmp 
upload_max_filesize = 300M
post_max_size = 300M
</code></pre>

<p>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).</p>

<p>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.</p>

<p>What can this be? What other PHP extensions can create temporary file in /tmp folder? </p>

<p>Thanks.</p>

<p><strong>Update 1.</strong>
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.</p>

<p>Can this problem be related to ob_* functions?</p>

<p><strong>Update 2.</strong>
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.</p>

<p><strong>Update 3.</strong>
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</p>

<pre><code>$fh=fopen('http://s3.amazonaws.com/.....');
</code></pre>

<p>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.</p>

<p>So the problem is only for php http wrapper and only on one my server (same code on other servers is fine).</p>

<p>This simple code demonstrates my problem:</p>

<pre><code>$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&gt;=$i*4194304){
            $i++;
            sleep(1);//just to make downloading slower
        }
    }
    fclose($_fp);
}
</code></pre>

<p>If i replace first line to</p>

<pre><code>$filepath='/path/to/local/file';
</code></pre>

<p>Then all is fine. Temp file is not created in /tmp folder</p>

<p>Any ideas about this strange problem?</p>
