RE: [PHP] How to detect a PHP script time-out?
| From: | Timothy Hitchens \(HiTCHO\) | Date: | Wed, 08 Jan 2003 06:34:14 +0000 |
| Subject: | RE: [PHP] How to detect a PHP script time-out? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-130714@lists.php.net to get a copy of this message | ||
There is one last option ... register an output buffer as I suggested
before suggested but this time do the reverse and you
don't have to rewrite your scripts:
<?php
ob_start('scriptTimeout');
// set to 1 this should show the error below set to 2 and above you
should get the normal output!!
set_time_limit(1);
function scriptTimeout($buffer)
{
if (eregi('Maximum execution', $buffer))
{
$buffer = 'Server Overloaded!!';
}
return $buffer;
}
//
// content area
//
for ($i = 0; $i < 1000000; $i++)
{
$output = $i;
}
echo 'We are upto a final count of: '.$output;
?>
Please be aware that this will add _some_ load but will solve your
issues. You can then add in things like error checking etc etc
Timothy Hitchens (HiTCHO)
Open Platform Consulting
e-mail: tim@hitcho.com.au
> -----Original Message-----
> From: Jean-Christian Imbeault [mailto:jc@mega-bucks.co.jp]
> Sent: Wednesday, 8 January 2003 3:43 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] How to detect a PHP script time-out?
>
>
> Timothy Hitchens ) wrote:
> > Issue... as I said before the register shutdown won't work because:
> >
> > - output from the shutdown is not visible nor do you have access to
> > some variables
>
> You are right. From the manual:
>
http://www.php.net/manual/en/function.register-shutdown-function.php
" The registered shutdown functions are called after the request has
been completed (including sending any output buffers), so it is not
possible to send output to the browser using echo() or print(), or
retrieve the contents of any output buffers using ob_get_contents()."
That's no good ...
There definitely should be a function that gets called (or can be
registered) when a script times out ... A time-out indicates an error on
my end (the server) and I would like to be able to detect it and take
action ...
If the is no way to do this then PHP is lacking. I'd definitely ask for
this to be implemented ;)
Jc
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php