Background php script times out after main page refresh (possible Mongoose issue or PHP?)

129 views
Skip to first unread message

Ally

unread,
Nov 20, 2016, 10:22:37 AM11/20/16
to PHP Desktop
Hi,

Firstly I'd like to say a huge thankyou for PHP Desktop, you've done a brilliant job - basically it just works, with everything I've thrown at it so far, and that includes some pretty complex scripts!   

Okay, so the only issue I'm having at the moment is getting PHP to respect the ignore_user_abort directive after a page refresh. I suspect it could be something to do with the way Mongoose is set up to deal with timeouts, but couldn't be sure, so read on to see what you think - this issue has been driving me mad for weeks and I still can't find a fix, so and it would be great if you had any clues as to what might be the problem.

So,for example, I have a main interface that is mostly updated via javascript and Ajax polling.  Let's say I click a button on the interface that triggers a script to begin collecting data via Ajax.. everything works fine, and as the script is running in the background the interface is updated on the fly with the results.  The script may need to run for several minutes or several hours before completion, but other features on the interface can still be accessed and all the while data from the script is pulled in via Ajax long polling and displayed on the fly in the interface as expected.  

However, if I click a basic HTML link on the interface to do a complete page refresh (just a standard <a href> tag to fully reload the page), upon reloading the background script that was pulling in the data eventually quits and doesn't complete. 

Now just to clarify: the script doesn't quit immediately after the page refresh, it continues as normal and the refreshed interface continues updating with the expected data too, but after around a minute, the interface will stop updating mid flow with no error messages to be found anywhere. (debug window tells me polling is continuing as expected, but the background script has quit)

I'm using ignore_user_abort(true), set_time_limit(0) in the script itself and max_input_time = -1 in PHP ini file too and everything works as expected when I run my app via my Apache based localhost in cefclient (3.2623.1401), Chromium 45, FF and IE. I can refresh the page, or infact close the browser altogether and reopen it altogether and the background script is still running fine on my localhost with Apache - but if running from within PHP Desktop, after a page refresh, the background collection script eventually quits after about 60 seconds after a page refresh. (NOTE: if I DON'T do a full page refresh, the script does continue and completes in PHP Desktop - it only quits after 60secs if I reload the page)

I'm currently using XP, so PHP Desktop is the latest RC version with PHP 5.4 (and I'm using pretty much all the same php ini settings for that as I am for my localhost)

Could the problem be a timeout setting in Mongoose or is there something else I night have missed? 

Any help greatly appreciated! 

Czarek Tomczak

unread,
Nov 20, 2016, 11:36:00 AM11/20/16
to PHP Desktop
There is a timeout option in Mongoose named "request_timeout_ms", but it's default value is 30 sec, so looks it is not related. Issue #17 plans to expose more options for Mongoose.

Have you tried to use PHP's program execution functions to execute php script in background? It's a blind shot, but you could try maybe it helps. For example: 1) make ajax request to php script1 2) script1 executes script2 by calling "php.exe script2.php". Looking at PHP program execution functions they seem to be executing under current process, as they all seem to do output. Maybe there is some option so that the process continues executing even if parent process is closed. Manual: http://php.net/manual/en/ref.exec.php

There is Issue #31 to expose useful Windows API functions to Javascript. One of these functions that might come in help here is "LaunchProcess". It would allow to create a process ("php.exe script2.php") that has phpdesktop-chrome.exe as the parent process. So the process would be guaranteed to run for app's lifetime.
Reply all
Reply to author
Forward
0 new messages