我怎样才能解析Apache的错误日志中的PHP? [英] How can I parse Apache's error log in PHP?
问题描述
我想创建解析或使Apache的错误日志的感觉,看看有什么最新的错误是一个脚本。我不知道是否有人在那里有东西做这个或有任何想法从哪里开始?
I want to create a script that parses or makes sense of apache's error log to see what the most recent error was. I was wondering if anyone out there has something that does this or has any ideas where to start?
推荐答案
有考虑几件事情第一:
- 首先,你的PHP用户可能无法访问到Apache的日志文件。
- 其次,PHP和Apache是不会告诉你在哪里说的日志文件,
- 最后,Apache日志文件会变得非常大。
但是,如果没有这些应用,你可以使用正常的文件读取命令去做。
拿到最后一个错误的最简单方法是
However, if none of these apply, you can use the normal file reading commands to do it. The easiest way to get the last error is
$contents = @file('/path/to/error.log', FILE_SKIP_EMPTY_LINES);
if (is_array($contents)) {
echo end($contents);
}
unset($contents);
有可能是这样做的更好的办法,不哼了记忆,但我会离开,作为一个练习留给读者。
There's probably a better way of doing this that doesn't oink up memory, but I'll leave that as an exercise for the reader.
最后一个评论:PHP也有一个ini设置PHP错误重定向到一个日志文件:的error_log = /path/to/error.log
One last comment: PHP also has an ini setting to redirect PHP errors to a log file: error_log = /path/to/error.log
您可以使用的php_flag符号设置这个在httpd.conf或.htaccess文件(如果你有机会到一个):
You can set this in httpd.conf or in an .htaccess file (if you have access to one) using the php_flag notation:
php_flag error_log /web/mysite/logs/error.log
这篇关于我怎样才能解析Apache的错误日志中的PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!