for a server with potentially long execution time, how to return result to a user timely and do not overload the server with excessive requests?
<p>I have a server with a web interface, through which a task is submitted to the server and the result is returned to the user as a web page. Sometimes the result is generated on the fly, sometimes it may take several hours. The result is written on disk and <code>check_status</code> function periodically checks whether the task is completed.
In the code given below it seems </p>

<pre><code>while ($status == 0) {
    sleep(x);
    $status = check_status($pars);
    ...
}
</code></pre>

<p>hangs up the server for big tasks when the user waits until his or her task will be completed.
What would be the optimal solution to return the result to the user timely and not overload
the server with excessive requests?
Set up a limit in the loop and terminate it? Or are there modern advanced technologies to<br>
handle these situations more efficiently?</p>

<pre><code>$status = check_status($pars);
if ($status == 1) {
    ...
    print $result;
}
else {
    print $reference_to_future_result; 
}

ob_flush();
flush();

while ($status == 0) {
    sleep(30);
    $status=check_status($pars);
    if ($status == 1) {
        ...
        change_page_content_to_result;
    }
}
...
</code></pre>
