Hang on browser stop button in middle of system() call

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pgalpern
Forum Newbie
Posts: 3
Joined: Fri Oct 01, 2010 9:24 am

Hang on browser stop button in middle of system() call

Post by pgalpern »

I am using PHP system() calls to run third party software. This software dumps output which is then forwarded to the browser synchronously. If the user hits the browser STOP button at the wrong time everything hangs, and all subsequent requests from that name-based virtual server (Apache) do not respond until the web server is restarted. Other virtual servers continue to work normally. Although a mySQL connection is involved, I do not think this is the problem as I can force closure of any open threads and the problem is not solved. I cannot, however, force closure of the process spawned by the system() call with Admin privs (on Windows 2003).

Can anyone:
(a) Tell me what they think is happening here; or
(b) Suggest a quick fix way to fix this without requiring restart

Thanks for you help.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Hang on browser stop button in middle of system() call

Post by pickle »

My immediate guess would be the culprit is the 3rd party software, or maybe IIS.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Hang on browser stop button in middle of system() call

Post by VladSun »

A quick fix:

Code: Select all

ignore_user_abort();
set_time_limit(0);
at the top of the page.

A real fix might be a Linux server :P
There are 10 types of people in this world, those who understand binary and those who don't
pgalpern
Forum Newbie
Posts: 3
Joined: Fri Oct 01, 2010 9:24 am

Re: Hang on browser stop button in middle of system() call

Post by pgalpern »

Yes--linux would be nice, however box needs to run Windows 2003. Apache/PHP instead of IIS are consolation prizes.

I tried ignore_user_abort() and set_time_limit(). Thank you for these suggestions. However this does not solve the problem. I also tried setting max_execution_time in configuration to 10 seconds, and it still does not recover after 10 seconds. Full Apache shutdown still required.

If it is the third-party software (happens to be R - statistical software interpreter) that is hanging, then how can I uncouple PHP (or is it Apache?) from hanging with it.

I am using system() calls rather than passthru() because I need R to send stuff to the browser synchronously. It is running long analyses, and it reports on its progress as it goes. passthru() only reports upon completion of the spawned process, it seems.

Thanks
pgalpern
Forum Newbie
Posts: 3
Joined: Fri Oct 01, 2010 9:24 am

Re: Hang on browser stop button in middle of system() call

Post by pgalpern »

Another possibility--could it be related to the fact that output buffering is _not_ being used in order that output from the third-party software is sent in real-time.
Post Reply