Get PHP error log with PHP

Is there a PHP function or some other way to get the PHP error log as a string?

I need this because I cannot access the error log on the site where I am running on another server. โ€œHe suggested writing me an error log, but thatโ€™s not very convenient.โ€

Is there any way to display the error log on the php page?


UPDATE

Now I understand that viewing the entire server error log will not actually be for me, however, I know that you can do something like this to send error_log instructions to yourself by email:

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

Is it possible to configure page errors for sending by email, and not display them?

+7
source share
1 answer

On a poorly protected server, yes. But on most servers there are two users: apache and [you]. You do not have access to the server logs, because they belong to the apache user (or no matter which server you use).

However, you could try:

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

Note. This is the default location on the Apache server based on RedHat. It could be different

Refresh To reflect an updated question
No, you cannot view the error log using error_log - this is a one-way process that is processed by the web server. It only writes a journal, but you cannot read it.

You can probably display errors:

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

You can even use set_error_handler to handle all warnings and notifications (for example, to send them). But thatโ€™s almost all you can do.

+8
source

All Articles