从PHP获取PHP错误日志 [英] Get PHP error log from PHP

查看:79
本文介绍了从PHP获取PHP错误日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有PHP函数或通过其他方式获取PHP错误日志作为字符串?

Is there a PHP function or some other way of obtaining the PHP error log as a string?

我需要这个,因为我无法访问我在其他人的服务器上运行的站点的错误日志. -他愿意通过电子邮件将错误日志发送给我,但这并不完全方便.

I need this because I cannot access the error log of a site I am running on someone else's server. - He offered to email me the error log but that isn't exactly convenient.

有什么方法可以将错误日志输出到php页面?

Is there some way I could output the error log to a php page?

更新

我现在意识到查看整个服务器的错误日志对我而言并不是真正的事情,但是,我知道您可以执行类似的操作以通过电子邮件将error_log手动致电发送给自己:

I now realize that viewing the entire server's error log is not really going to happen for me, however, I know you can do something like this to email a manual error_log call to yourself:

error_log('A really bad error',3,'me@myemail.com');

是否可以将页面配置为通过电子邮件向您发送错误而不是显示错误?

Is it possible to configure a page to email errors to you instead of displaying them?

推荐答案

在安全性较差的服务器上,可以.但是在大多数服务器上有两个用户:apache和[you].您无权访问服务器日志,因为它们由apache用户(或您使用的任何服务器)拥有.

On a badly secured server, yes. But on most servers there are two users: apache and [ you ]. You don't have access to the server logs, since they are owned by the apache user (or whichever server you're using).

但是,您可能可以尝试一下:

However, you could probably try it:

echo file_get_contents('/var/log/httpd/error_log');

注意:这是基于RedHat的apache服务器上的默认位置.可能会有所不同

更新 以反映更新后的问题
不,您不能使用error_log查看错误日志-这是由Web服务器处理的单向过程.它仅写入日志,但您无法读取它.

Update To reflect the updated question
No, you cannot view the error log with error_log - it is a one-way process that gets handled by the webserver. It only writes the log, but you cannot read it.

您可能会显示以下错误:

You can probably display the errors with this:

ini_set('display_errors', 'On');
error_reporting(E_ALL);

您甚至可以使用 set_error_handler 处理所有警告和注意事项(针对例如,邮寄给他们).但这几乎就是您所能做的.

You could even use set_error_handler to handle all warnings and notices (for example, to mail them). But that's pretty much all you can do.

这篇关于从PHP获取PHP错误日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆