简体   繁体   English

哪些PHP扩展将临时文件写入/ tmp文件夹?

[英]What PHP extensions write temp files to to /tmp folder?

I have problem on my web server. 我的网络服务器上有问题。

I noticed that often big files are created in /tmp directory. 我注意到通常在/ tmp目录中创建大文件。 Files are like /tmp/phpUNIQUECODE But these are not uploads. 文件类似于/ tmp / phpUNIQUECODE,但这些不是上载。 Because in my php.ini settings configuration is 因为在我的php.ini设置中配置是

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). 我发现/ tmp中的文件是由PHP进程在下载文件时写入的(PHP进程从TCP套接字读取文件并写入输出)。

I read some PHP manuals and i see that tehre is PHP function tmpfile(). 我阅读了一些PHP手册,并且看到tehre是PHP函数tmpfile()。 It creates temp file in /tmp folder (even if upload_tmp_dir is different ). 它在/ tmp文件夹中创建临时文件(即使upload_tmp_dir不同)。 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? 还有哪些其他PHP扩展可以在/ tmp文件夹中创建临时文件?

Thanks. 谢谢。

Update 1. IN my download function i use ob_start and ob_flush functions. 更新1.在我的下载函数中,我使用ob_start和ob_flush函数。 ob_flush is calles after every 4kb of data are posted to a browser. 每隔4kb数据发布到浏览器后,就会调用ob_flush。

Can this problem be related to ob_* functions? 这个问题可以和ob_ *函数有关吗?

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. 更新2。我发现在其他服务器上执行相同的PHP代码以下载文件的/ tmp文件夹中没有临时文件。 So this must be related to php.ini settings or apache settings. 因此,这必须与php.ini设置或apache设置相关。 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. 下载完成后,将从/ tmp文件夹中删除临时文件。

Update 3. I isolated this problem. 更新3.我隔离了此问题。 I found thsi is not problem of downloading. 我发现这不是下载问题。 This is problem of reading files with PHP HTTP wrapper. 这是使用PHP HTTP包装程序读取文件的问题。 My files are stored on amazon s3. 我的文件存储在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). 我也测试了其他包装器-ftp和一些自定义包装器(例如,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). 因此,问题仅在于php http包装器,并且仅位于我的一台服务器上(其他服务器上的相同代码也可以)。

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 在/ tmp文件夹中未创建临时文件

Any ideas about this strange problem? 关于这个奇怪的问题有什么想法吗?

as cryptic said it sounds like php sessions, in your php.ini check to see the value of 正如神秘人士所说,这听起来像是php会话,请在您的php.ini中检查一下的值

session.save_path 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? 好的,大概不是会话文件,我已经重读了您的OP和您的多余注释,并且该文件是由下载数据的脚本创建的,并且在脚本完成后被清除了,这是什么问题?

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. 我还要指出,设置upload_tmp_dir用于通过HTTP上传文件(根据默认php.ini中的注释),因此大概与下载无关。 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. 由于/ tmp文件与下载文件的大小和时间匹配,因此确实看起来是操作系统在整理数据时存储文件的方式。 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 它很有可能会假脱机到光盘上以保留系统RAM

updated 2 更新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. 也许我指的是操作系统不完全正确,也许是在PHP胆量中的某个地方选择了名称/创建了tmp文件。 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. 根据您所说的一切,我看到的底线是这里没有问题,这就是PHP的工作方式。

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. 可能将另一台服务器设置为在其他地方写入tmp文件,但是如果您没有实际提供用于检查的代码片段,我看不到有人可以如何帮助您获得更多详细信息。

What problem are these tmp files causing you? 这些tmp文件导致您什么问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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