473,790 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to handle PHP execution timeouts gracefully?

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?

Thanks in advance,
Joannès
http://www.lokad.com, sales forecasting

Mar 21 '07 #1
2 19190
"Joannes Vermorel" <jo************ **@gmail.comwro te:
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 http://www.php.net/manual/en/control...es.declare.php
For example:

define("MAX_EXE CUTION_TIME", 10); # seconds

$timeline = time() + MAX_EXECUTION_T IME;

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

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

register_tick_f unction("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

Mar 21 '07 #2
Thank you for your answer. We will what we can do with the declare()
method that you're suggesting.

Joannes
http://www.lokad.com

Mar 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2083
by: Rich | last post by:
Hi all, I'm trying to write an app to monitor an IIS server, by connecting and getting a page via httplib. the problem seems to be when IIS (or ASP) dies httplib does not always return and sometimes I'm left with an app that hangs. what is the best way to handle this ? thanks, rich.
5
1753
by: Ximo | last post by:
Hello, I'm programing an advanced calculator, and I have many problems with the execution errors, specually with the division by 0. And my question is how can show the execution error whitout exit of the program, showing it in the error output as >>2+2 >>4 >>3*4 >>12
9
2358
by: Joe Rigley | last post by:
Hello, As a .NET newbie I'd appreciate some advice... I've been tasked with writing a small app (in VB .NET) that takes some data from our HR system, does some format modifications, and loads that into Active Directory. For error handling of this app, I was considering having the app process each employee one at a time. If an error occurs, I was thinking that the system would handle the error with a Try/Catch, send the error details...
1
6421
by: Zri Man | last post by:
The Error in play is CLI Driver] SQL30020N Execution failed because of a Distributed Protocol Error that will affect the successful execution of subsequent commands and SQL statements: Reason Code "". SQLSTATE=58009 sqlstate = 40003 My Target is a DB2/UDB 8.2.2 database on SuSE Linux. This has been happening regularly.
2
363
by: Fraijo | last post by:
how can i disable session timeouts without affecting any program codings?
17
3305
by: Chaprasi | last post by:
Hi I need help with prototype while doing ajax calls. So this is my JS which does a ajax calls var ajax1 = new Ajax.Request ( url, { method: 'get', parameters: params, onComplete: showResults, onFailure: showFailure
6
2053
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in your business layer and/or data access layer? suppose in my data access layer, I provide try and catch, log the exception and re-throw it back to business layer, then in yoru business layer, what do you do? throw it back to the code behind or...
2
3047
by: Richard | last post by:
Hello all, I am looking into issues with time-outs on a website. These appear to happen in a random way for some users. This is one example: Fatal error: Maximum execution time of 60 seconds exceeded in auth.php on line 5 auth.php contains:
4
1220
by: Giampaolo Rodola' | last post by:
Hi, I'm trying to implement an asynchronous scheduler for asyncore to call functions at a later time without blocking the main loop. The logic behind it consists in: - adding the scheduled functions into a heapified list - calling a "scheduler" function at every loop which checks the scheduled functions due to expire soonest Note that, by using a heap, the first element of the list is always
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7530
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.