Re: Fatal Error Handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 9 Feb 2005 08:21:25 -0800 (PST), Richard Lynch <ceo@xxxxxxxxx> wrote:
> James Taylor wrote:
> 
> So finally quit that music thing and got a real job? :-)
> 
> [Sorry.  I'm sure you've heard them all, but I couldn't resist...]
> 
> >   I have a set of functions which are potentially dangerous in terms of
> > memory hogging, and need to protect from memory overflow - this is I
> > want to detect when the memory overflow occurs.
> >
> > The manual says that eval() will return false on a fatal error, so I
> > thought I could do something like the following, where it would produce
> > a "O" for each itteration, and when it failed (memory overflow) it would
> > continue and echo the last line. What I get however is this attached to
> > the end.
> >
> > Any advice would be gratefully recieved (and perhaps, the documentation
> > on eval updating if it can not catch all fatal errors)
> >
> > #! /usr/bin/php
> > <?php
> >   $y = 0;
> >   $str = "";
> >   $code = '$str .= $str . "."; return true;';
> >   $x = TRUE;
> >   while($x != FALSE){
> >    $x = eval($code);
> >    echo "O";
> >    $y ++;
> >   }
> >    echo "\n $y it's \n\n ". $str;
> > ?>
> >
> > run:
> > $ ./intellirun2.php
> > OOOOOOOOOOOOOOOOOOOOOO
> > Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
> > allocate 4194305 bytes) in
> > /home/jt/work2/sms/web/stats/intellirun2.php(8) : eval()'d code on line 1
> 
> You may or may not have some success by preceding the eval with a @ and/or
> using http://php.net/error_reporting and/or using
> http://php.net/set_error_handler to trap the error.
> 
> If you are using PHP 5, a try/catch block may also be useful to consider.
> 
> I suspect that eval() DOES return false, once you get the error_reporting
> under control instead of relying on the rather crude default error
> handling.
> 
> --
> Like Music?
> http://l-i-e.com/artists.htm
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
I think a try catch block wouldn't be enough, as most functions throw
warning messages instead exceptions.

You should set a custom error handler and throw the exception by
yourself, if you want to.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux