Re: How to handle PHP execution timeouts gracefully?



"Joannes Vermorel" <joannes.vermorel@xxxxxxxxx> wrote:

We have developed an open-source eCommerce sales forecasting add-on in
PHP (see link below) that requires usually more than a few seconds to
complete because the process involves some Web Services
communications.
http://community.lokad.com/PhpSalesForecasting.ashx

Yet, in shared hosting with short PHP execution timeouts, our script
may not terminate (being killed by the web server).

Our concern is not the timeout in itself, it's the fact that this
situation is very confusing for the user who may not even be aware
that a timeout has been encountered and who may experience random bugs
due to this timeout.

Thus we need to handle gracefully the PHP execution timeouts by
displaying appropriate and meaningful error messages.

Do anyone knows how to do that?

Two solutions:

1) You said that some other web services are involved, so your program acts
as a sort of gateway between the remote client and those services. Maybe the
504 error "Gateway timeout" of the HTTP protocol is appropriate in this case.

2) Using declare(), see www.php.net/manual/en/control-structures.declare.php
For example:

define("MAX_EXECUTION_TIME", 10); # seconds

$timeline = time() + MAX_EXECUTION_TIME;

function check_timeout()
{
if( time() < $GLOBALS['timeline'] )
return;

# timeout reached:
echo "<html><html>Sorry, we are very busy, retry later!</body></html>";
exit;
}

register_tick_function("check_timeout");

declare( ticks=1 ){
# here the process that might require
# so much time; any output generated is
# keep inside a string $s
}

# Ok, process completed, output the result:
echo $s;


Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

.



Relevant Pages

  • web service timeout issue. please help.
    ... I have a web client code written in C# and I am using web services ... Only timeout I am using this case ... Uri dest = new ...
    (microsoft.public.dotnet.languages.csharp)
  • System.Net.WebException: The operation has timed out
    ... I have a web client code written in C# and I am using web services ... Only timeout I am using this case ... Uri dest = new ...
    (microsoft.public.dotnet.framework.webservices)
  • Timeout expired
    ... I am using Service Component in my ASP.NET Application, Web Services is ... I am using Enterprise Service to handle transaction and AutoComplete at ... Timeout expired. ... * I delete my component from Component Manager and ReRegister It. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Publishing schema as web service... client side timeout problem
    ... Client side gets timeout error. ... I am using 2003 server and 2.0 framework. ... Web services generated with the Web Services Publishing Wizard in BizTalk ...
    (microsoft.public.biztalk.general)
  • How to handle PHP execution timeouts gracefully?
    ... We have developed an open-source eCommerce sales forecasting add-on in ... complete because the process involves some Web Services ... Yet, in shared hosting with short PHP execution timeouts, our script ...
    (comp.lang.php)