简体   繁体   中英

Get PHP error log from 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.

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


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('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 ]. 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');

Note: that's the default location on a RedHat-based apache server. 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. 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). But that's pretty much all you can do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM