我发现奇怪的行为php
and /tmp
文件夹。 Php 在使用时使用另一个文件夹/tmp
。 PHP 5.6.7、nginx、php-fpm。
我以两种方式执行相同的脚本:通过浏览器和通过 shell。但是当通过浏览器启动时,文件不是真实的/tmp
folder:
<?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
I get
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
?
Because systemd 配置为给 nginx 一个私有的 /tmp http://0pointer.de/blog/projects/security.html。如果你must由于某种原因使用系统 /tmp,那么您将需要修改 .service 文件以读取“PrivateTmp=no”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)