29517

Way to determine/circumvent if an AJAX request timed out?

Question:

I have a simple web-page (PHP, JS and HTML) that is displayed to illustrate that a computation is in process. This computation is triggered by a <em>pure</em> JavaScript AJAX-request of a PHP-script doing the actual computations. For details, please see <a href="https://stackoverflow.com/questions/7606330/confusing-php-ajax-timeout-after-900-secs15-mins" rel="nofollow">here</a>

What the actual computation is, does not play a role, so for simplicity, it is just a sleep()-command.

When I execute the same code locally (browser calls website under localhost: linux, apache, php-mod) it works fine, independant of the sleep-time.

However, when I let it run on a different machine (not localhost, but also Linux, apache, php-mod), the PHP-script does run through (results are created), but the AJAX-request does not get any response, so there is no "onreadystatechange" if the sleep-time is >= 900 seconds. When sleep-time < 900 seconds it also works nicely and the AJAX-request is correctly terminated (readyState==4 and status==200).

The apache and php-configuration are more or less default and I verified the crucial options there already (max_execution_time etc.) but none seems to be valid here as they are either shorter (<1 min.) or bigger, e.g. for the garbage-collector (24 min.).

So I am absolutely confused what may cause this. I am thinking it might be network-related, although I didn't find any appropriate option in my router or so. Also no error is reported in the apache-logs or in PHP (error loggin to file).

Letting the JavaScript with the AJAX-request display the request.status upon successfull return, surprisingly when I hit "Esc" in the browser window after the sleep is over, I also get the status "200" displayed but not automatically as it should do it.

In any case, I am hoping that you may have an idea how to circumvent this problem? Maybe some dummy-communication between client and server every 10 minutes or so might do the trick, but I don't have an idea how to best do something like this, especially letting this be transparent to the user and not interfering with the actual work of doing the computations/sleep.

Best,

Shadow

P.S. The post that I am referencing is written by me, but seems to tramsit the idea that it might be related to some config-option, which seems <em>not</em> to be the case. This is why I am writing this post here, basically asking for a way to circumvent such an issue regardless of it's origin.

Answer1:

I'm from the other post you mentioned!

Now that I know more about what you are trying to do: monitor a possibly long running server job, I can recommend something which should turn out a lot better, its not a direct answer to your question, but its a design consideration which includes by its nature a more suitable solution.

Basically, unlink the actions of "starting" the server side task, from monitoring its progress.

<ul><li>execute.php kicks off your background job on the server, and immediately returns.</li> <li>Another script/URL (lets call it status.php) is available to check the progress of the task execute.php is performing. <ul><li>When status.php is requested, it won't return until it has something to report, UNLESS 30 seconds (or some other fixed) amount of time passes, at which point it returns a value that you know means "check again". Do this in a loop, and you can be notified immediately of when the background task has completed.</li> </ul></li> </ul>

More details on an approach similar to this: <a href="http://billhiggins.us/blog/2011/04/27/resty-long-ops" rel="nofollow">http://billhiggins.us/blog/2011/04/27/resty-long-ops</a>

I hope this help give you some design ideas to address your problem!

Recommend

  • CSS method instead of display:run-in; to position a block inline?
  • What is the possible benefit (if any) of allowing recursive constructors?
  • Add-In Commands Ribbon shows in Excel Online but not in Excel for Windows
  • Creating A C# & XNA 'Monster Dash' Like Game
  • What is the ClojureScript analogue of delete from JavaScript?
  • Getting SerializeObject to use JsonProperty “name” defined inside interface
  • Execute a piece of code from the data-section
  • Net-ssh session timeout
  • Java : Simple XML not parsing the xml. Gives Exception
  • Update varbinary(MAX) field in SQLServer 2012 Lost Last 4 bits
  • remove unicode characters but keep all special and English characters with preg_replace
  • Can't remove headers after they are sent
  • Symfony 2. CSRF token is invalid
  • Spring Cloud Microservice Architecture Confusion
  • D3 get axis values on zoom event
  • Connect .sks to skscene.h
  • Unable to decode certificate at client new X509Certificate2()
  • How to use JavaScript to determine whether a file exists in a directory?
  • Custom validator control occupying space even though display set to dynamic
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Can you perform a UNION without a subquery in SQLAlchemy?
  • JSON response opens as a file, but I can't access it with JavaScript
  • MongoDB in PHP using aggregate to group by _id is null not working
  • CSS Linear-gradient formatting issue accross different browsers
  • Why is an OPTIONS request sent to the server?
  • How can I send an e-mail from a vbs script
  • Spring security and special characters
  • Deleting and Updating values from a cusrsor adapter
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Modifying destination and filename of gulp-svg-sprite
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • Release, debug version and Authorization Google?
  • GridView Sorting works once only
  • Is there a mandatory requirement to switch app.yaml?
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • apache spark aggregate function using min value
  • UserPrincipal.Current returns apppool on IIS