Php fwrite或error_log无法使用CLI处理后台任务&;
我有一个基本的php脚本,可以写入/记录文本文档Php fwrite或error_log无法使用CLI处理后台任务&;,php,error-handling,background-process,fwrite,Php,Error Handling,Background Process,Fwrite,我有一个基本的php脚本,可以写入/记录文本文档 <?php $filename = 'php_log.log'; $somecontent = 'writing with fwrite!'.PHP_EOL; if (is_writable($filename)) { if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; }
<?php
$filename = 'php_log.log';
$somecontent = 'writing with fwrite!'.PHP_EOL;
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
error_log('logging with error_log!'.PHP_EOL,3,'php_log.log');
?>
在CLI中,如果我执行php test.php
并检查php_log.log,我将看到这两种写入。
但是当我尝试php test.php&
时,没有任何内容写入php\u log.log
是否有我不知道的php设置?
谢谢 可能是没有锁定。
为什么要手动写入文件,然后使用
错误日志
- 考虑使用
替换为file\u-put\u-contents()
。它只附加到文件的末尾并负责锁定file\u-APPEND | file\u-LOCK
- 启用
并将error\u reporting
重定向到单独的文件以了解更多信息stderr
php test.php 2>php\u errors.txt&