Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: mod_fcgid and user abort |
|
Author |
|
drake127
Joined: 23 Feb 2012 Posts: 3
|
Posted: Thu 23 Feb '12 11:14 Post subject: mod_fcgid and user abort |
|
|
Hello,
I have been trying to set up one PHP application on Windows using Apache with mod_fcgid and I encountered some strange behaviour I consider a bug in mod_fcgid or PHP.
The application I use relies heavily on a need to finish its work no matter what client does so I run PHP with ignore_user_abort set.
When running on mod_php, it ensures that PHP does not terminate after client closes TCP connection, I expected same behaviour on mod_fcgid but was wrong on both Linux and Windows world (moreover the mod_fcgid behaviour differs).
When serving a new request, a PHP process is spawned as usual and set as busy. However if user aborts a request, the socket is closed and the process is set to an idle state while still executing the script.
This is terribly wrong as next request is sent to that "idle" proccess,immediately fails with connect error and is scheduled for termination. Termination won't be responded to and so fcgid forcibly kills the process next round it makes its checks.
The interestingly enough, when I tested this on Linux, it worked (but I also used different versions of packages in Debian Squeeze). The detached process was kept in busy state until it reached its timeout.
I looked into a source code of PHP and mod_fcgid as this is really a showstopper for me but failed to locate a problem (I have only so much knowledge of Apache and PHP source). Is somebody able to point me to right direction or help with this bug? I am not sure who to blame but I certainly need this one resolved.
Thanks.
Last edited by drake127 on Thu 23 Feb '12 11:38; edited 1 time in total |
|
Back to top |
|
drake127
Joined: 23 Feb 2012 Posts: 3
|
Posted: Thu 23 Feb '12 11:24 Post subject: |
|
|
Here is my configuration and details: Code: | Apache 2.2.22 VC9 x64
mod_fcgid 2.3.7-al x64 (also confirmed on 2.3.6-pl2, 2.3.6d and x86 variants)
PHP 5.3.10 VC9 NTS x64 (also confirmed on PHP 5.4.0 RC7 NTS x64 and x86 variants) |
mod_fcgid configuration: Code: | FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 256
FcgidInitialEnv PHPRC "C:/Program Files/PHP"
FcgidBusyScanInterval 60
FcgidErrorScanInterval 60
FcgidIdleScanInterval 60
FcgidZombieScanInterval 60
FcgidBusyTimeout 86400
FcgidIdleTimeout 60
FcgidProcessLifeTime 0
FcgidIOTimeout 86400
FcgidMaxProcesses 32
FcgidMinProcessesPerClass 4
FcgidMaxProcessesPerClass 32
FcgidMaxRequestInMem 1048576
FcgidMaxRequestLen 67108864
FcgidOutputBufferSize 8192
FcgidMaxRequestsPerProcess 256
FcgidFixPathinfo 0 |
php.ini configuration: Code: | ;cgi.force_redirect = 1
;cgi.nph = 1
;cgi.redirect_status_env = ;
;cgi.fix_pathinfo=1
;fastcgi.impersonate = 0;
;fastcgi.logging = 0
;cgi.rfc2616_headers = 0 |
sample PHP script: Code: | <?php
ignore_user_abort(true); // set here or in php.ini
while (true) // this is gonna be a really long script
{
for ($i = 0; $i < 256; ++$i) // we want to flush fcgid buffer often so it can catch closed connection
echo md5(mt_rand());
sleep(1); // and we do not want it to choke either.
} |
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Thu 23 Feb '12 16:43 Post subject: |
|
|
I'm not sure idle means the script is not running. I tried your test script on the command line.
php.exe run_test.php. The CPU usage on that process was zero. (well I know it is about the sleep. without the sleep the usage would be see able in the taskmanager).
A good test scenario would be to write each time in the loop with file_put_contents the time into a log file and see if it realy stops. |
|
Back to top |
|
drake127
Joined: 23 Feb 2012 Posts: 3
|
Posted: Thu 23 Feb '12 18:40 Post subject: |
|
|
You are right, I haven't need such check because my application itself is doing some file writes and was killed several minutes later (expected was about an hour).
The script continues to execute (and writes to a file) even when flagged as Idle or Error by fcgid until it is eventually killed.
I forgot to post some logs: Code: | ### A new request ###
[Thu Feb 23 17:30:31 2012] [info] mod_fcgid: server localhost.cz:C:/Progra~1/PHP/php-cgi.exe(8056) started
### I aborted the request after receiving first bunch of data. ###
[Thu Feb 23 17:30:38 2012] [info] [client 192.168.56.1] (OS 10053)An established connection was aborted by the software in your host machine. : core_output_filter: writing data to the network
### I reloaded the page, so another request is sent and fcgid attempts to reuse an "idle" process. It does not respond as it is still busy with the first request.
[Thu Feb 23 17:30:41 2012] [debug] fcgid_proc_win.c(301): [client 192.168.56.1] (OS 121)The semaphore timeout period has expired. : mod_fcgid: can't connect to named pipe, FastCGI server pid 8056
### A new process is spawned to accommodate the second request. ###
[Thu Feb 23 17:30:42 2012] [info] mod_fcgid: server localhost.cz:C:/Progra~1/PHP/php-cgi.exe(1568) started
### I aborted the second request as well. ###
[Thu Feb 23 17:30:47 2012] [info] [client 192.168.56.1] (OS 10053)An established connection was aborted by the software in your host machine. : core_output_filter: writing data to the network
### Fcgid attempts to terminate the first process since it thinks it crashed (idle process didn't respond to a request). ###
[Thu Feb 23 17:32:29 2012] [debug] fcgid_pm_main.c(357): mod_fcgid: gracefully terminated 1 processes
### Fcgid means it. ###
[Thu Feb 23 17:34:29 2012] [warn] mod_fcgid: process 8056 graceful kill fail, sending SIGKILL
[Thu Feb 23 17:36:29 2012] [info] mod_fcgid: process C:/Progra~1/PHP/php-cgi.exe(8056) exit(connect error, server may has exited), return code 9 |
The second process continues to run even as idle until fcgid determines it does not need idle process or it fails to respond. |
|
Back to top |
|
|
|
|
|
|