r/PHPhelp • • Mar 23 '21

I can't understand the PHP error system.

I am using the docker image php:7.4-fpm. I have managed to configure php-fpm even though most of the options I do not understand them.. Here is the configuration:

[global]
error_log = /var/log/php-fpm.log
daemonize = no
log_level = notice
log_limit = 8192
[www]
listen = 9000
clear_env = no
catch_workers_output = yes
decorate_workers_output = no
.....
....

I actually changed the configuration so that I send it to a file (/var/log/php-fpm.log) instead of sending it stdeer and stdout. So far so good.

Now I'm going with the PHP configuration, this is my configuration

php.ini
error_reporting = E_ALL 
display_errors = On 
log_errors = On ; 
; error_log = /var/log/php-errors.log

I have commented the error_log directive to know the behavior of this system, obviating the Syslog type because I don't want to go into that. I want to know what happens when you do not put anything in error_log, the documentation says that it is

errors are sent to the SAPI error logger

No idea what that is, but I searched with this explanation. https://stackoverflow.com/a/23286225/2046442,

In summary it says that it sends it to the parent system of the logs such as Apache or Nginx in my case, well that only see errors on the screen, how can I do to see it in Nginx or send it to another system like Monolog?

Nginx configuration

server{error_log /var/log/nginx/web_error.log;

access_log /var/log/nginx/web_access.log;

}

None of these files contain the PHP errors that I am causing.I do NOT know if you can help me to orient in the right path.

7 Upvotes

12 comments sorted by

6

u/HolyGonzo Mar 23 '21

It's not going to go to Nginx because you're using PHP-FPM. The PHP-FPM process is the one that is running the script (Nginx simply tells PHP-FPM what script is being requested).

So if you don't specify the error_log in your php.ini file and you trigger an error, it'll bubble up to PHP-FPM's error logging, and at that point, it's completely up to FPM to determine where and how to log it. The snippet you have at the top seems like it should be recording errors into /var/log/php-fpm.log (you need to restart FPM after any config changes).

Although in all honesty, I think letting errors bubble up into parent logs is a bad idea. That just means you're mixing different kinds of logs together, and that can lead to confusion. It's better to specify error_log in your php.ini file and point it to a separate file so your PHP script errors are kept separate.

I'll note that there's a dozen different ways to configure logging, and since configurations can be split up into multiple files / pieces, it's going to be hard to know 100% for sure if there isn't something else overriding error handling or changing the handling of STDERR.

1

u/chiqui3d Mar 23 '21

Exactly, really and most likely I send the errors to a file, but I want to understand the error_log directive when you have commented it. As you say I have PHP-FPM, but the errors are still not seen in the file generated by /var/log/php-fpm.log, I only see this:

[23-Mar-2021 20:55:14] NOTICE: fpm is running, pid 8

[23-Mar-2021 20:55:14] NOTICE: ready to handle connections

I mean php-fpm logs, not PHP logs, so I need to see that behaviour to understand that from the log system parent or SAPI Error Logger.

2

u/HolyGonzo Mar 23 '21

I'm wondering if you're expecting regular errors to go that way, too. For example, if you had a syntax error in a file.

The way you have it configured should work as long as you're specifically writing to the STDERR pipe. For example, if you wrote a line of code:

error_log("hello world");

...then you should see a line in your /var/log/php-fpm.log file like this:

[23-Mar-2021 19:36:10] WARNING: [pool www] child 12345 said into stderr: "hello world"

BUT you're not going to see things like fatal errors by default, because those aren't routed to STDERR by default. If you want to route those kinds of errors to STDERR, just set the "display_errors" setting in php.ini to "stderr":

display_errors = stderr

...and reload PHP-FPM.

2

u/chiqui3d Mar 24 '21

error_log("hello world");

This what it says if it does the behaviour you say. It is also included in the nginx error file, but now I have put a syntax error like:

$template ------="Hello"

And this error is displayed on screen, but not anywhere else. I have configured as you say, see this output:

docker-compose exec php php -i | grep error

display_errors => STDERR => STDERR

display_startup_errors => On => On

error_append_string => no value => no value

error_log => no value => no value

error_prepend_string => no value => no value

error_reporting => 32767 => 32767

html_errors => Off => Off

ignore_repeated_errors => Off => Off

log_errors => On => On

log_errors_max_len => 1024 => 1024

track_errors => Off => Off

xmlrpc_error_number => 0 => 0

xmlrpc_errors => Off => Off

intl.error_level => 0 => 0

opcache.error_log => no value => no value

Thank you very much indeed for helping me to understand, it seems that I'm getting closer to a full understanding.

2

u/HolyGonzo Mar 24 '21

Did you reload PHP-FPM? If display_errors is set to stderr and you're seeing the error on the screen, then something isn't reading the updated php.ini file (or maybe there's caching or something).

3

u/chiqui3d Mar 24 '21

You are right, that the problem comes from Symfony Framework(I chose a bad testing site), I'm investigating. I'm going to sleep. Tomorrow I'll see if I can find out more. I owe you a big one. I'll pay you back if I have to.

5

u/HolyGonzo Mar 24 '21

You're welcome. I'm assuming by "I owe you a big one" that you'll be sending me a check in the mail for $32,000. It seems excessive but I'll take it.

2

u/ArlinnKordd Mar 23 '21 edited Mar 23 '21

No idea if this is helpful since sysadmin is not my ballpark at all, but if you're trying to find the destination I've seen errors (on Apache) go to such places as

/var/log/php-fpm/www-error.log

/var/log/httpd/<documentrootfolder>/error_log/

/var/log/httpd/default/ssl_error_log/

I just grab them with cat -n and | tail -50. Others may know more or r/sysadmin may be able to help better

1

u/chiqui3d Mar 23 '21

Thank you very much. I have done the search:

find . -name \*.log -ls | sort -r -n -k7

Both in the nginx container and in the PHP container and I can't find anything about the PHP errors, it must be something in the configuration that I'm missing.

1

u/ArlinnKordd Mar 23 '21

That is very odd. What does the config say? I think it's supposed to be listed under php_admin_value[error_log]

Is this helpful?

0

u/[deleted] Mar 23 '21

[deleted]

1

u/chiqui3d Mar 23 '21

Your configuration is fine, but I'm not looking to have a log file configured error_log, I want to see the behaviour when you have nothing set, as I said above that according to PHP sends it to the parent system ior SAPI Error Loggin, and I want to see the behaviour of the last one in order to understand it.

1

u/albo87 Mar 23 '21

The configs looks good to me. Check the permissions of the log file. You can create it if it doesn't exists.