Stut wrote:
Henning Eiben wrote:
Tijnema ! wrote:
I have a small sample-application, that uses smarty for the
presentation
layer. Unfortunately I might encounter script-timeouts (not necessarily
from smarty, could also be the DB-connection or something). In this
case
I would like to return an appropriate HTTP status-code (might be 500 or
something). Right now I just receive a blank page, as well as a HTTP
status-code of 200, which would indicate that everything is OK!
So what do I need to do?
I don't think this is possible in PHP. But i guess you need to do
something in Apache, to return some special error message. A thing to
keep in mind:
PHP max_execution_time set in php.ini or set with set_time_limit does
not affect system calls, such as database operations.
So, you'd be better off setting the time limit in Apache, and do some
stuff with Apache configuration files to return something.
Well, looking at my "error.log" in my PHP directory tells me, that
several php-files exceeded maximum scripting time. That's why I asked.
And I observed receiving a blank page, which is not satisfying ... so
what would I do in Apache (or IIS) to get an error-code (HTTP code
that is)?
Use register_shutdown_function to, erm, register a shutdown function.
Call ob_start at the very top of the script. Initialise $finished to
false on the line after that. At the end of the script set it to true.
If your shutdown function gets called and $finished is false then the
script did not finish. Call ob_end_clean and output the header/body to
return the HTTP error code you want.
Oh, I forgot to add that you should look at the set_time_limit function
as a possible means to avoiding the script ending. When I write a script
that will sit in a loop that could potentially loop a lot I'll call
set_time_limit with a reasonable time allowed for a single loop
execution. This means as long as the script is actually doing something
it will not time out.
-Stut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php