I try to run a Yii based PHP application in a Docker container using the official php-fpm image.
It's common practice for docker containers to write all log messages to stdout / stderr. So I do the same from my container with a code that basically looks like this:
$fp = #fopen('php://stdout','w');
fwrite($fp, $message);
fclose($fp);
Unfortunately PHP-FPM now prefixes all my log messages with ugly warnings:
[21-Mar-2016 14:10:02] WARNING: [pool www] child 12 said into stdout: "2016-03-21 14:10:02 [x.x.x.x][-][-][trace][yii\base\Application::bootstrap] Bootstrap with yii\debug\Module::bootstrap()"
[21-Mar-2016 14:10:02] WARNING: [pool www] child 12 said into stdout: "2016-03-21 14:10:02 [x.x.x.x][-][-][info][yii\web\Session::open] Session started"
...
Why is this and is there a way to prevent PHP-FPM from doing this?
UPDATE:
I've also opened an issue at the docker-library/php project site.
They already include the catch_workers_output = yes in their configuration. So that's not the solution.
According to these changes the problem should be fixed in PHP 7.3
It is correct. you are running php-fpm and error logs are from php-fpm , not from PHP .
you should expect php-fpm log , not php log. fortunately php-fpm will write every log that received from PHP in end of its logs.
Related
In error log i found warnings something like that
WARNING: [pool www] server reached pm.max_children setting (10), consider raising it
So I changed it in conf file /etc/php/7.0/fpm/pool.d/www.conf to 52 after some recommended calculations.
After this I restarted apache and I thought that problem was resolved. But right now I see again in error log file same warning with same value 10.
So I have a question - how can I check current pm.max_children? If it is not 52 then I will try to inspect why it is not applying.
It is an old post, surely you have already solved it in the meantime. In any case, maybe the problem was that you also had to restart php-fpm to make the changes effective with something like this:
sudo service php7.0-fpm restart
After increasing number of queue workers via Supervisor and php artisan queue:work, sometimes I get:
WARNING: [pool www] server reached pm.max_children setting (10), consider raising it
Does anyone know if php artisan queue:work caused the warning above?
You can change the value of max_children from here:
/etc/php/8.0/fpm/pool.d/www.conf
Please note the PHP version and OS and change the path to match yours.
But when you say sometimes, it sounds you have slow PHP scripts.
probably a pretty simple question but how do I change the log format for FPM logs? An Entry looks like this for im in stderr:
2017/12/12 10:59:09 [error] 17#17: *6 FastCGI sent in stderr: "PHP message: 2017-12-12 11:59:09 > WARNING > WarningId: 1234 []
The thing I want to remove is the [error] part because in this example I'm logging a warning via monolog.
Since PHP 7.3 you can use
[www]
catch_workers_output = yes
decorate_workers_output = no
in php-fpm.conf (or php-fpm.d/ or pool.d/, depends on your system) to remove some extra decoration
Php fpm doesn't seem to have a config for this error logging format.
You could stop logging errors altogether by changing the logging level setting.
By a quick look into php-fpm sources it seems that it's the php error log format that is used for that.
And you do have control over that. One solution would be writing your own error handler
Problem
When xdebug server is running from IntelliJ IDEA, I get 502 Bad Gateway from nginx when I try loading my site to trigger breakpoints.
If I stop the xdebug server, the site works as intended.
So, I'm not able to run the debugger, but it did work previously (!). Not able to pinpoint why it suddenly stopped working.
Setup
A short explanation of the setup (let me know if I need to expand on this).
My php app is running in a docker container, and it is linked to nginx running in a different container using volumes_fromin the docker compose config.
After starting the app, I can verify using phpinfo(); the xdebug module is loaded.
My xdebug.ini has the following content:
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=10.0.2.2
xdebug.remote_connect_back=0
xdebug.remote_port=5555
xdebug.idekey=complex
xdebug.remote_handler=dbgp
xdebug.remote_log=/var/log/xdebug.log
xdebug.remote_autostart=1
I got the ip address for remote_host (where the xdebug server is running) by these steps:
docker-machine ssh default
route -n | awk '/UG[ \t]/{print $2}' <-- Returns 10.0.2.2
To verify I could reach the debugging server from within my php container, I did the following steps
docker exec -it randomhash bash
nc -z -v 10.0.2.2 5555
Giving the following output depending on xdebug server running or not:
Running: Connection to 10.0.2.2 5555 port [tcp/*] succeeded!
Not running: nc: connect to 10.0.2.2 port 5555 (tcp) failed: Connection refused
So IntelliJ IDEA is surely set up to receive connections on 5555. I also did the appropriate path mapping between my source file paths and the remote path (when setting up the PHP Remote Debugging server from within IDEA).
Any ideas? Kind of lost on this one as I don't have much experience with any of these technologies :D
This sometimes happens, the reason is the errors in php-fpm and xdebug (exactly)!
When I refactored my colleagues code, оne page on the project returned 502 Bad Gateway
Here's what I found:
php-fpm.log
WARNING: [pool www] child 158 said into stderr: "*** Error in `php-fpm: pool www': free(): invalid size: 0x00007f1351b7d2a0 ***"
........
........
WARNING: [pool www] child 158 exited on signal 6 (SIGABRT - core dumped) after 38.407847 seconds from start
I found a piece of code that caused the error:
ob_start();
$result = eval("?>".$string."<"."?p"."hp return 1;");
$new_string = ob_get_clean();
But that is not all. The error occurred only in a certain state $string which at first glance, did not differ from the others. In my case, everything is simple. I removed the code that caused the error. This did not affect the functionality of the web page. I continued to debug the code further.
I had the same problem with the Vagrant Homestead Parallels box with a Silicon chip. Switching from php 7.3 to 7.4 fixed the issue for me.
I'm trying to setup an php-fpm daemon to send error_log to syslog.
My config php-fpm.conf looks thereby.
error_log = syslog
syslog.facility = local4
syslog.ident = php-fpm
Restarting php-fpm daemon I can see in the remote syslog server.
Mar 22 00:32:08 192.168.33.14 php-fpm[20919]: [NOTICE] configuration file /etc/php5/fpm/php-fpm.conf test is successful
Good!
But when I test this with a real php script with errors, message change to..
Mar 22 00:05:59 192.168.33.14 ool www[20889]: PHP Parse error: syntax error, unexpected ''api'' (T_CONSTANT_ENCAPSED_STRING) in /var/api/public/index.php on line 2
ool www is pool + default pool name (www). So two questions:
Why I see ool www instead of php-fpm (syslog.ident value)?
Why is pool title is truncated?
I think its a PHP bug :(
See please
https://bugs.php.net/bug.php?id=67764
This issue will become more prevalent as we start to upgrade older systems to php 5.5+, so posting for future reference.
Here is the fix we used, put it as low level as you can so all your scripts can benefit:
// This was needed for upgrade to php5.5+ with php-fpm
// Source: https://gist.github.com/gjuric/e0c9e45efb3d15e3b949
// Bug History: http://stackoverflow.com/questions/22575152/sending-errors-to-syslog-in-php-fpm
openlog('php', LOG_ODELAY, LOG_USER);