Note that there are some explanatory texts on larger screens.

plurals
  1. POConfusing PHP/AJAX timeout after 900 secs(15 mins)
    primarykey
    data
    text
    <p>all of the below is based on Linux, recent Apache, recent PHP module for Apache.</p> <p>I am experiencing an unexpected behavior for my AJAX+PHP based web-application. It is quite a simple AJAX approach, basically involving a request to a PHP-script (execute.php) that runs for some time (few seconds to several minutes). As a test-setup, the PHP-script (execute.php) basically just sleeps for a certain amount of time. When this amount is 899 seconds, it works, but when I set it to 900, the answer of the PHP-script (simple echo() ) seems to expire or something like this (what is exactly the cause or reason is actually unknown to me) as the request is not taking notice of it and thus not responding and the respective innerHTML is not updated, as expected. Please find the code below.</p> <p>I am now wondering where this "timeout" of 900 seconds comes from and even more important, how can I prevent that from happening? After all, I thought that this was, at least, one general idea of AJAX to handle asynchronous calls and notify the client as soon as a request has changed its state?!</p> <p>process.php</p> <pre><code>&lt;?php session_start(); include("functions.php"); include("env.php"); html_head("Processing..."); $sid = $_SESSION['my_sid']; ?&gt; &lt;script type="text/javascript"&gt; function run_analyses(params){ &lt;?php print "var sid = \"". $sid ."\"; "; ?&gt; // Use AJAX to execute the programs independenantly in the background // Allows for the user to close the process-page and come back at a later point to the results-link, w/o need to wait. if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); } else { //Fallback for IE5 and IE6, as these don't support the above writing/code http_request = new ActiveXObject("Microsoft.XMLHTTP"); } //Is http_request still false if (!http_request) { alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen'); } http_request.onreadystatechange=function(){ if (http_request.readyState==4 &amp;&amp; http_request.status==200){ // Maybe used to display the progress of the execution document.getElementById("output").innerHTML=http_request.responseText; } }; http_request.open("POST","execute.php",true); //Send the proper header information along with the request http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.setRequestHeader("Content-length", params.length); http_request.setRequestHeader("Connection", "close"); http_request.send(params); }; &lt;/script&gt; &lt;?php $params "some_params"; print " Starting AJAX-call&lt;br&gt; &lt;div style=\"width:400px; border: 1px black solid;\" id=\"output\"&gt;Use this to display an information about the progress&lt;/div&gt; &lt;script type=\"text/javascript\"&gt; run_analyses('".$params."'); &lt;/script&gt; &lt;form action=\"./usersets/". $sid ."/results.html\" id=\"go_to_results\" method=\"POST\"&gt; &lt;input type='hidden' name=\"session_id\" value=\"" .$sid. "\"&gt; &lt;/form&gt; "; html_foot(); ?&gt; </code></pre> <p>and execute.php:</p> <pre><code>&lt;?php session_start(); include("functions.php"); include("env.php"); $sid = $_SESSION['my_sid']; // Used to get the time at start of processing $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $start = $time; session_write_close(); sleep(900); //899 here works session_start(); $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 3); //echo 'Page generated in '.$total_time.' seconds.'."\n"; // Make it accessible for the results $_SESSION['process_time'] = $total_time; echo("none"); ?&gt; </code></pre> <p>So the text after "Starting AJAX call" is updated to "none" when the PHP-script sleeps for 899 seconds, but stays "Use this to display an information about the progress" if that value is 900 seconds.</p> <p>I am really looking forward to your suggestions.</p> <p>Best,</p> <p>Shadow</p> <p><strong>EDIT</strong></p> <p>Doing <code>grep max_execution $(locate php.ini )</code> gives:</p> <pre><code>/etc/php5/apache2/php.ini:max_execution_time = 30 /usr/share/doc/php5-common/examples/php.ini-development:max_execution_time = 30 /usr/share/doc/php5-common/examples/php.ini-production:max_execution_time = 30 /usr/share/php5/php.ini-production:max_execution_time = 30 /usr/share/php5/php.ini-production-dist:max_execution_time = 30 /usr/share/php5/php.ini-production.cli:max_execution_time = 30 </code></pre> <p><strong>EDIT2</strong> When calling the scripts locally (apache webserver running on my local linux machine) in my browser interestingly it behaves as expected and respectes the return of the request. But it exhibits the above unexpected behavior when run on a webserver running on a different machine. Any clues on that? Because I don't have any... Sorry.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload