我发现了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'));
Run Code Online (Sandbox Code Playgroud)
php -f script.php
File /tmp/185617.txt
bool(true)
string(38) "CentOS Linux release 7.0.1406 (Core)
Run Code Online (Sandbox Code Playgroud)
文件在哪里?在/ tmp
$ find / -name 185617.txt
/tmp/185617.txt
Run Code Online (Sandbox Code Playgroud)
如果通过http://myserver.ru/script.php我获取它
File /tmp/185212.txt
bool(true)
string(38) "CentOS Linux release 7.0.1406 (Core)
Run Code Online (Sandbox Code Playgroud)
但文件在哪里?
$ find / -name 185212.txt
/tmp/systemd-private-nABCDE/tmp/185212.txt
Run Code Online (Sandbox Code Playgroud)
为什么php认为/tmp应该在/tmp/systemd-private-nABCDE/tmp?
我有一个 Codeigniter 应用程序,我在其中记录错误、调试和信息消息。在 config.php 中,我将阈值设置为 4。我可以在 application/log 文件夹中看到日志文件。现在我尝试从控制器的方法中添加自定义日志。我用了
log_message("error", "this is my custom error");
Run Code Online (Sandbox Code Playgroud)
但这不是在日志文件中记录。到目前为止我尝试过的
没有写日志。在现有的日志文件中,我可以看到来自核心文件的日志消息。我无法从应用程序文件夹中写入任何内容。