php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73056 shell_exec cause PHP FPM child processes exit and start very quickly forever
Submitted: 2016-09-09 11:26 UTC Modified: 2018-02-23 20:48 UTC
Votes:9
Avg. Score:4.9 ± 0.3
Reproduced:9 of 9 (100.0%)
Same Version:3 (33.3%)
Same OS:5 (55.6%)
From: samer dot mhana at gmail dot com Assigned:
Status: Duplicate Package: FPM related
PHP Version: 7.0.10 OS: Ubuntu 16.04.1 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
23 + 1 = ?
Subscribe to this entry?

 
 [2016-09-09 11:26 UTC] samer dot mhana at gmail dot com
Description:
------------
Dear sirs

I have installed php 7.0.10 on my Ubuntu server. PHP run in FPM mode with nginx. PHP does not have user load (only me) since I am working privately on new project

PHP configuration is minimal. some standard extensions along with pecl xdebug, redis and maxmind.

The weird problem that happens: PHP child processes keeping exit and restart continuously without stop. Here are some of the lines of my FPM log (Debug):

*********************************************************************
[09-Sep-2016 12:51:00.158151] NOTICE: pid 15821, fpm_children_make(), line 421: [pool php7-admin] child 1156 started
[09-Sep-2016 12:51:00.158164] DEBUG: pid 15821, fpm_event_loop(), line 419: event module triggered 1 events
[09-Sep-2016 12:51:00.161542] DEBUG: pid 15821, fpm_event_loop(), line 419: event module triggered 2 events
[09-Sep-2016 12:51:00.161571] DEBUG: pid 15821, fpm_got_signal(), line 76: received SIGCHLD
[09-Sep-2016 12:51:00.161585] NOTICE: pid 15821, fpm_children_bury(), line 252: [pool php7-admin] child 1154 exited with code 0 after 0.011634 seconds from start
[09-Sep-2016 12:51:00.162047] NOTICE: pid 15821, fpm_children_make(), line 421: [pool php7-admin] child 1157 started
[09-Sep-2016 12:51:00.162065] DEBUG: pid 15821, fpm_event_loop(), line 419: event module triggered 1 events
[09-Sep-2016 12:51:00.165706] DEBUG: pid 15821, fpm_event_loop(), line 419: event module triggered 2 events
[09-Sep-2016 12:51:00.165733] DEBUG: pid 15821, fpm_got_signal(), line 76: received SIGCHLD
[09-Sep-2016 12:51:00.165748] NOTICE: pid 15821, fpm_children_bury(), line 252: [pool php7-admin] child 1155 exited with code 0 after 0.011767 seconds from start
[09-Sep-2016 12:51:00.166188] NOTICE: pid 15821, fpm_children_make(), line 421: [pool php7-admin] child 1158 started
[09-Sep-2016 12:51:00.166201] DEBUG: pid 15821, fpm_event_loop(), line 419: event module triggered 1 events
[09-Sep-2016 12:51:00.169747] DEBUG: pid 15821, fpm_event_loop(), line 419: event module triggered 2 events
[09-Sep-2016 12:51:00.169773] DEBUG: pid 15821, fpm_got_signal(), line 76: received SIGCHLD
[09-Sep-2016 12:51:00.169786] NOTICE: pid 15821, fpm_children_bury(), line 252: [pool php7-admin] child 1156 exited with code 0 after 0.011643 seconds from start
*************************************************

There are millions of line in that log files that are created in just few hours. 

After I restart PHP Master process,  everything return normal for few hours. After that I find high CPU load for the master process, and check the log to find this outcome.

I tried to unload extensions, changing "pm" to static and back to ondemand. But always the same result (PHP FPM goes crazy after few hours).

Here is my PHP-FPM conf

[global]
emergency_restart_threshold = 100
emergency_restart_interval = 1d
error_log = log/php-fpm-admin.log
log_level = debug

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;

[php7-admin]
user = myuser
group = myuser
listen = /home/myuser/php7-admin.sock
listen.owner = myuser
listen.group = nogroup
listen.mode = 0660
listen.backlog=2000
pm = static
pm.max_children = 3
pm.process_idle_timeout = 10
pm.max_requests = 2000
security.limit_extensions = .php
catch_workers_output = yes


I really need to resolve this issue before I move on in my project. I searched the whole bug system and internet if anything can help with no luck. I only found (somehow similar) bug https://bugs.php.net/bug.php?id=70185




Test script:
---------------
No test script. it Just happens without executing specific script.

Expected result:
----------------
Expected that PHP-FPM only kill child processes after reaching pm.process_idle_timeout > 10 seconds OR pm.max_requests > 2000 in "ondemand" or only after reaching the pm.max_requests in static mode.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-09 14:58 UTC] samer dot mhana at gmail dot com
-Summary: PHP FPM child processes keep exit and start very very quickly (continuously) +Summary: shell_exec cause PHP FPM child processes exit and start very quickly forever
 [2016-09-09 14:58 UTC] samer dot mhana at gmail dot com
I found what trigger this behavior. PHP function "shell_exec" and "exec" cause this "craziness" to start and continue. But not with all shell commands. In my case, Only when I execute the following line:

shell_exec('cleancss /home/statics/my.css');

OR this line:

exec('cleancss /home/statics/my.css');

However, all the shell commands that I tried (such as ls, cat uglifyjs ....) does not cause the problem.

Now I think that this problem strongly related to this: https://bugs.php.net/bug.php?id=70185.
 [2016-10-14 11:40 UTC] robing at transip dot nl
This seems to be caused by the fact that the program you execute sets STDIN to non-blocking. We encountered it with passthru and ssh, and eventually managed to reproduce it by executing the following php script in passthru:

<?php
stream_set_blocking(STDIN, false);
echo "Blah";
?>
 [2016-10-14 13:15 UTC] robing at transip dot nl
So after some more experimenting we managed to 'solve' this by using proc_open instead in combination with pipes instead of one of the exec family functions.
 [2017-08-22 12:13 UTC] tarasov dot igor at gmail dot com
This is an old issue that stands from php 5 to 7.1. Here are other bug reports that have almost the same behavior:

https://bugs.php.net/bug.php?id=61558
https://bugs.php.net/bug.php?id=70185

This is critical bug, since in default configuration PHP-FPM quickly fills up all available space with its logs (speed depends on number of CPUs), thus bringing down entire server. All you need is some broken pipe in executed code via exec, for instance, and voila, soon your server will be down. But php-fpm still manages to serve new requests, so you won't notice it until it is too late, unless you have some alerts on CPU load set up.

Can it finally be solved, please?
 [2018-02-23 20:48 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2018-02-23 20:48 UTC] nikic@php.net
Same issue as bug #73342, marking as duplicate.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 11:01:30 2024 UTC