这里有一个基本的测试脚本来显示我遇到的问题:
test1.php
<?php
error_log('hello');
?>
这很好用。开放http://exmaple.com/test将"hello"记录到/var/log/apache2/error.log中。
现在我有了这个,在后台运行test.php:
test2.php
<?php
shell_exec("/usr/bin/php /var/www/test.php > /dev/null 2>/dev/null &");
?>
我知道在这个例子中stderr
被重定向到/dev/null
,但我也尝试过不使用> /dev/null 2>/dev/null &
,但仍然没有日志记录。
我还尝试使用ini_set('error_log','/var/log/apache2/error.log');
在test.php中设置error_log路径
有没有办法让它正确登录?
这对我有效
<?php
ini_set('error_log', '/home/user/error.log');
error_log('hello');
输出:
[27-Jun-2015 11:20:55 UTC] hello
当您从控制台运行脚本时,请确保您有权写入日志文件。