Bug #71209 [Opn->Nab]: php-cgi script hangs when started from php-fpm via system(), passthru() etc.

From: Date: Fri, 15 Jul 2016 10:12:31 +0000
Subject: Bug #71209 [Opn->Nab]: php-cgi script hangs when started from php-fpm via system(), passthru() etc.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202351@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71209&edit=1 ID: 71209 Updated by: dmitry@php.net Reported by: lameventanas at gmail dot com Summary: php-cgi script hangs when started from php-fpm via system(), passthru() etc. -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: 5.6.16 / 7.0.1 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2016-03-17 09:12:31] 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-01-05 02:10:23] lameventanas at gmail dot com Fixed versions. ------------------------------------------------------------------------ [2015-12-25 06:24:02] lameventanas at gmail dot com Disregard my previous comment, the same thing happens with 5.6.2, and even 7.0.1. ------------------------------------------------------------------------ [2015-12-24 10:44:19] 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-24 03:17:25] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71209&edit=1

« previous php.bugs (#202351) next »