php-cli在Mac 10.15上的何处记录错误



我快速开发了一个本地脚本&dirty并让它在命令行上运行。我没有安装服务器。

我的php.ini位于/usr/local/etc/php/7.4/php.ini

我使用激活了错误日志

error_reporting = E_ALL
display_errors = On
log_errors = On
error_log = /var/log/php_errors.log

我保存了更改,但没有在/var/log/php_errors.log 中找到日志

我必须做些什么才能将错误记录到文件中

输出

$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/ext-opcache.ini

$ which php
/usr/local/bin/php

我的理解是php-cli将错误输出到命令行的方式与bash脚本非常相似。因此,您可以以相同的方式将错误输出到自己的日志文件中。

这里是一个简单的脚本文件error_test.php,它有两个命令。第一个回显字符串-第二个回显未定义的变量,这将产生错误:

<?php
echo "hellon";
echo $test;

以的身份运行脚本

php error_test.php

并且它将输出以下内容:

hello
PHP Notice:  Undefined variable: test in /home/phi/Projects/sandbox/error_test.php on line 3

像bash脚本一样,我们可以将stderr输出重定向到具有2>的文件

php error_test.php 2> error.log
cat error.log

这将在每次运行命令时替换日志文件。要将错误附加到日志文件,请使用2>>

php error_test.php 2>> error.log

要忽略错误,请重定向到/dev/null

php error_test.php 2>> /dev/null

最新更新