PHP error_log &包括不工作
所以,我的问题如下。当我通过网络浏览器加载页面时,此代码工作正常。但是当我从命令行运行脚本时,如下所示:“php script.php”它会爆炸。
script.php 是:
<?php
include_once('class.WebsiteScraper.php');
$ws = new WebsiteScraper();
$ws->test();
...
?>
class.WebsiteScraper.php 是:
<?php
echo 'test';
class WebsiteScraper {
public function test() {
echo 'test2';
}
}
?>
这会返回错误:
PHP 致命错误:调用未定义 方法 WebsiteScraper::test() 在 ... 第 4 行
仅当通过命令行调用时才会发生这种情况。 另一件需要注意的事情是,当我附加
error_log('hey there');
To script.php 时,它会将错误抛出到标准输出,而不是在我的错误日志中。但是当从网络浏览器调用时,它会将其放入错误日志中。有什么想法吗?
So, my problem is as follows. This code works fine when I load the page via the web browser. But when I run the script from the command line like so: "php script.php" it bombs.
script.php is:
<?php
include_once('class.WebsiteScraper.php');
$ws = new WebsiteScraper();
$ws->test();
...
?>
class.WebsiteScraper.php is:
<?php
echo 'test';
class WebsiteScraper {
public function test() {
echo 'test2';
}
}
?>
This returns the error:
PHP Fatal error: Call to undefined
method WebsiteScraper::test()
in
...
on line 4
Only when called via the command line does this happen.
Another thing to note, when I append an
error_log('hey there');
To script.php, it throws the error to the standard out, rather than in my error log. But when called from the web browser it puts it in the error log. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用命令行选项
--ini
检查命令行是否加载与 apache 相同的配置文件:您还可以调用
phpinfo()
。您的文件似乎没有被包含 - 可能是由于包含路径。
编辑:
尝试添加
Use the command line option
--ini
to check if the command line is loading the same configuration file as apache:You could also call
phpinfo()
.It seems likely your file isn't being included - probably due to include paths.
Edit:
Try adding