[英]Get PHP error log from PHP
Is there a PHP function or some other way of obtaining the PHP error log as a string? 是否有PHP函数或其他一些获取PHP错误日志作为字符串的方法?
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.
- 他提议给我发错误日志,但这不太方便。
Is there some way I could output the error log to a php page? 有什么方法可以将错误日志输出到php页面吗?
UPDATE UPDATE
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
调用给自己:
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? 是否可以将页面配置为向您发送电子邮件错误而不是显示它们?
On a badly secured server, yes. 在一个安全性很差的服务器上,是的。 But on most servers there are two users: apache and [ you ].
但在大多数服务器上有两个用户:apache和[you]。 You don't have access to the server logs, since they are owned by the apache user (or whichever server you're using).
您无权访问服务器日志,因为它们由apache用户(或您正在使用的服务器)拥有。
However, you could probably try it: 但是,您可以尝试一下:
echo file_get_contents('/var/log/httpd/error_log');
Note: that's the default location on a RedHat-based apache server. 注意:这是基于RedHat的Apache服务器上的默认位置。 It may be different
可能会有所不同
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. 不,您无法使用
error_log
查看错误日志 - 它是由Web服务器处理的单向进程。 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);
You could even use set_error_handler
to handle all warnings and notices (for example, to mail them). 您甚至可以使用
set_error_handler
来处理所有警告和通知(例如,邮寄它们)。 But that's pretty much all you can do. 但这几乎是你所能做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.