php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71209 php-cgi script hangs when started from php-fpm via system(), passthru() etc.
Submitted: 2015-12-24 03:17 UTC Modified: 2016-07-15 10:12 UTC
From: lameventanas at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.6.16 / 7.0.1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lameventanas at gmail dot com
New email:
PHP Version: OS:

 

 [2015-12-24 03:17 UTC] lameventanas at gmail dot com
Description:
------------
My lighttpd server uses fastcgi to run php code.

The php code starts an external program that happens to be a standalone php script (shebang: #!/usr/bin/php-cgi).

The script hangs when started from a php-fpm process manager, but works fine when started from a php-cgi "process manager".

Just to clarify, the process that hangs is the php-cgi which is interpreting the standalone script.  If I replace this with a shellscript, everything works fine.

Test script:
---------------
test.php:
<?
header("Content-type: text/plain");
echo "Starting\n";
system("/var/www/htdocs/script.php");
echo "Finished\n";
?>

script.php:
#!/usr/bin/php-cgi -q
<?
echo "Hello world!\n";
?>


Expected result:
----------------
No hangs.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-24 10:44 UTC] lameventanas at gmail dot com
This didn't happen with 5.6.2, but I'm uncertain of which version introduced the change.

Note that /usr/bin/php-cgi is SAPI cgi-fcgi.
was compiled with --disable-cli and --enable-cgi.

If I use #!/usr/bin/php in script.php (CLI SAPI), it doesn't hang.
 [2015-12-25 06:24 UTC] lameventanas at gmail dot com
-PHP Version: 5.6.16 +PHP Version: 5.6.16 7/.0.1
 [2015-12-25 06:24 UTC] lameventanas at gmail dot com
Disregard my previous comment, the same thing happens with 5.6.2, and even 7.0.1.
 [2016-01-05 02:10 UTC] lameventanas at gmail dot com
-PHP Version: 5.6.16 7/.0.1 +PHP Version: 5.6.16 / 7.0.1
 [2016-01-05 02:10 UTC] lameventanas at gmail dot com
Fixed versions.
 [2016-03-17 09:12 UTC] lameventanas at gmail dot com
I found that php-cgi is stuck trying to call accept() on stdin:

...
22730 rt_sigaction(SIGPIPE, {SIG_IGN, [PIPE], SA_RESTART}, {SIG_IGN, [PIPE], SA_RESTART}, 8) = 0
22730 brk(0x882d000)                    = 0x882d000
22730 gettimeofday({1458204368, 785265}, NULL) = 0
22730 open("/tmp/.ZendSem.FT3dUS", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
22730 fchmod(3, 0666)                   = 0
22730 fcntl64(3, F_GETFD)               = 0
22730 fcntl64(3, F_SETFD, FD_CLOEXEC)   = 0
22730 unlink("/tmp/.ZendSem.FT3dUS")    = 0
22730 mmap2(NULL, 67108864, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|0x40000, -1, 0) = -1 ENOMEM (Cannot allocate memory)
22730 mmap2(NULL, 67108864, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0) = 0xae200000
22730 fcntl64(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=1}) = 0
22730 time(NULL)                        = 1458204368
22730 fcntl64(3, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=1}) = 0
22730 fcntl64(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=1}) = 0
22730 fcntl64(3, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=1}) = 0
22730 brk(0x884e000)                    = 0x884e000
22730 accept(0, 

So I changed my test script to:

system("/var/www/htdocs/script.php < /dev/null");

and it doesn't hang anymore!
 [2016-07-15 10:12 UTC] dmitry@php.net
-Status: Open +Status: Not a bug
 [2016-07-15 10:12 UTC] dmitry@php.net
You use php-cgi to run CLI script, but when you start it from FPM process, php-cgi thinks - it's a FastCGI server itself and waits for requests on STDIN.

Use php instead of php-cgi.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 04:00:01 2026 UTC