我发现有关 php
和 /tmp
文件夹的奇怪行为。 Php 在使用 /tmp
时使用另一个文件夹。 PHP 5.6.7,nginx,php-fpm。
我以两种方式执行相同的脚本:通过浏览器和通过 shell。但是当它通过浏览器启动时,文件不在真正的 /tmp
文件夹中:
<?php
$name = date("His");
echo "File /tmp/$name.txt\n";
shell_exec('echo "123" > /tmp/'.$name.'.txt');
var_dump(file_exists('/tmp/'.$name.'.txt'));
var_dump(shell_exec('cat /etc/*release | tail -n 1'));
php -f script.php
File /tmp/185617.txt
bool(true)
string(38) "CentOS Linux release 7.0.1406 (Core)
文件在哪里?在/tmp
$ find / -name 185617.txt
/tmp/185617.txt
如果通过 http://myserver.ru/script.php
访问它,我得到
File /tmp/185212.txt
bool(true)
string(38) "CentOS Linux release 7.0.1406 (Core)
但是文件在哪里?
$ find / -name 185212.txt
/tmp/systemd-private-nABCDE/tmp/185212.txt
为什么 php 认为 /tmp
应该在 /tmp/systemd-private-nABCDE/tmp
中?
最佳答案
因为 systemd is configured to give nginx a private /tmp .如果出于某种原因您必须改用系统/tmp,那么您将需要修改 .service 文件以读取“PrivateTmp=no”。
关于php通过nginx访问时在/tmp/systemd-private-nABCDE/tmp中有自己的/tmp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30444914/