Re: Fatal Error Handling

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

 



James Taylor wrote:
> Richard Lynch wrote:
>> James Taylor wrote:
> Ok, using the @ that would get rid of the error message agreed, but it
> still crashes the script (as a fatal error would and should). I took the
> code from set_error_handler and that does not seem to work in this
> instance - if I called the function with trigger_error then yes, it was
> ok, but the memory fail still caused the crash.

I think it's still going to die on you...

<?php
        ini_set('memory_limit', '32K');
        ini_set('error_reporting', 0);
        echo "Memory Limit: ", ini_get('memory_limit'), "\n";
        echo "Memory Used: ", memory_get_usage(), "\n";
        function error_handler($error, $message, $file, $line){
                echo "Error ($error) in $file:$line - $message\n";
                return true;
        }

        set_error_handler('error_handler');
        trigger_error("Test", E_USER_NOTICE);

        $str = str_repeat('a', 1024);
        while (true){
                echo '.';
                flush();
                $str .= $str;
        }
        echo "\nMade it!\n";
?>

-bash-2.05b$ php test.php
Content-type: text/html
X-Powered-By: PHP/4.3.10

Memory Limit: 32K
Memory Used: 13432
Error (1024) in /www/l-i-e.com/web/test.php:12 - Test
....-bash-2.05b$

Note a complete lack of "Made it" nor an error message trapped by my error
handler when the RAM runs out. :-(

Looks like the Memory limit is hard-coded and won't trigger an error
handler nor will it give you any chance to catch it.

You *DO* have access to memory_get_usage, so you could check on your
memory available to find out what's going on...

> There are other possible solutions which we may end up implementing
> which include a success monitor, ie each run enteres into a database a
> "start" and a "end" and then at some other time, another script can
> check for scripts that have started but not ended (ie crashed) and
> provide analysis, alerts and fixes for.

Looks like you're stuck with this.

> With error handling as normal, can it handle a fatal error? My issue is
> not it would not report a fatal error, it does not continue with the
> script.

I think maybe not -- but maybe only specific errors exhibit this feature.

Memory limit and Time limit could be "weird" enough to need it.

You could try some other fatal errors to see.

> The last issue I am worried about is scope - if I have run out of
> memory, then what can I do - I seem to have issues running commands
> which go over this limit during the command (irrelevant of their end
> memory usage). Supposing I had enough memory to run the set_ini function
> and increase my memory limit, then I would be able to execute any
> command to roll back (transaction wise) the program execution so far,
> and email/notify/whatever. This is irellevant if a "success" orientated
> monitoring method is implemented.

I think you would be well-served to figure out where the RAM is going, and
making sure it's what it should be at various junctures.

Maybe you're trying to patch symptoms instead of debugging the true problem.

Just a thought.

You could also maybe file this as a bug, after searching the bugs database
to see if it's a known issue, or even a "feature"

-- 
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


[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