Reply to Re: [PHP] Fatal Error Handling

Your name:

Reply:


Posted by Richard Lynch on 02/09/05 18:21

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация