我正在运行 xubuntu 12.04,使用 apache2 作为本地服务器。我最近在“testing.php”中编写了一个 while 循环语句,该语句应该从 url 检索远程 xml 文件并将其保存到位于本地服务器上的文件中。我运行此代码时没有意识到循环是无限的。浏览器开始加载,几秒钟后我的电脑开始明显变慢,直到停止快速运行。我重新启动电脑。我检查 error.log 文件,加载此文件需要约 30 秒,与其他访问相比不寻常。加载“error.log”文件后,它开始显示与此 while 循环相关的数百行错误。所以我立即删除该行代码并完全修复它。现在程序已修复并正常运行,但每次我打开“error.log”时,都需要一段时间才能打开,并且会记录相同的错误。即使我在打开“error.log”之前没有运行“testing.php”
以下是一些被记录的错误,请记住我知道为什么会出现这些错误,但我只是不知道为什么这些错误仍然被记录下来:
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: count in /home/sebastian/jasone_co/Testing/testing.php on line 96
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: file_get_contents(jasoneatherly.tumblr.com/api/read/?type=photo&&start=0&&num=25): failed to open stream: No such file or directory in /home/sebastian/jasone_co/Testing/testing.php on line 85
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fopen(/home/sebastian/jasone_co//Testing/Test-XML/TumblrXML_0-25.xml): failed to open stream: No such file or directory in /home/sebastian/jasone_co/Testing/testing.php on line 86
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/sebastian/jasone_co/Testing/testing.php on line 87
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /home/sebastian/jasone_co/Testing/testing.php on line 88
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "/home/sebastian/jasone_co//Testing/Test-XML/TumblrXML_0-25.xml" in /home/sebastian/jasone_co/Testing/testing.php on line 90
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Notice: Trying to get property of non-object in /home/sebastian/jasone_co/Testing/testing.php on line 91
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Notice: Trying to get property of non-object in /home/sebastian/jasone_co/Testing/testing.php on line 91
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: count in /home/sebastian/jasone_co/Testing/testing.php on line 96
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: file_get_contents(jasoneatherly.tumblr.com/api/read/?type=photo&&start=0&&num=25): failed to open stream: No such file or directory in /home/sebastian/jasone_co/Testing/testing.php on line 85
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fopen(/home/sebastian/jasone_co//Testing/Test-XML/TumblrXML_0-25.xml): failed to open stream: No such file or directory in /home/sebastian/jasone_co/Testing/testing.php on line 86
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/sebastian/jasone_co/Testing/testing.php on line 87
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /home/sebastian/jasone_co/Testing/testing.php on line 88
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "/home/sebastian/jasone_co//Testing/Test-XML/TumblrXML_0-25.xml" in /home/sebastian/jasone_co/Testing/testing.php on line 90
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Notice: Trying to get property of non-object in /home/sebastian/jasone_co/Testing/testing.php on line 91
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Notice: Trying to get property of non-object in /home/sebastian/jasone_co/Testing/testing.php on line 91
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: count in /home/sebastian/jasone_co/Testing/testing.php on line 96
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: file_get_contents(jasoneatherly.tumblr.com/api/read/?type=photo&&start=0&&num=25): failed to open stream: No such file or directory in /home/sebastian/jasone_co/Testing/testing.php on line 85
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fopen(/home/sebastian/jasone_co//Testing/Test-XML/TumblrXML_0-25.xml): failed to open stream: No such file or directory in /home/sebastian/jasone_co/Testing/testing.php on line 86
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/sebastian/jasone_co/Testing/testing.php on line 87
[Sun May 27 22:07:49 2012] [error] [client 127.0.0.1] PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /home/sebastian/jasone_co/Testing/testing.php on line 88
我也尝试过定位任何僵尸进程或已停止运行的进程,但无济于事。运行时得到的结果如下ps -C apache2
:
sebastian@Lucight:~$ ps -C apache2
PID TTY TIME CMD
2875 ? 00:00:00 apache2
2880 ? 00:00:00 apache2
2881 ? 00:00:00 apache2
2882 ? 00:00:00 apache2
2883 ? 00:00:00 apache2
2884 ? 00:00:00 apache2
2901 ? 00:00:00 apache2
2903 ? 00:00:00 apache2
2904 ? 00:00:00 apache2
2905 ? 00:00:00 apache2
2906 ? 00:00:00 apache2
正如我之前所说,重新启动计算机对于解决这个问题没有作用。
答案1
首先尝试查看该文件的大小。可能它太大了,打开它需要时间。
执行tail -f error.log
以查看脚本是否仍然产生错误。
执行tail error.log
还应该告诉最后的条目是从什么日期开始的。
如果 tail 显示没有记录错误,那么您可以安全地删除该文件(如果文件太大)。(一些错误日志的大小可达 GB)。
您可以使用命令清除该error.logcat /dev/null > error.log
但是如果尾部显示错误仍然记录...嗯,那么我会说某处仍然存在需要修复的错误。
我的回答更多的是猜测,因为你提供的信息并不清楚原因