问题
I have a simple script:
<?php
$source = '../path/img.jpg';
$image = imagecreatefromjpeg($source);
?>
Finally I got:
Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted
But when I try do something like that:
<?php
$source = '../path/img.jpg';
$image = @imagecreatefromjpeg($source); // Mute Fatal Error
if ( !$image )
{
die('Image file is too large');
}
?>
but it doesn't work. Fatal error is stopping my script. Is any way to change this situation? I would like to know when fatal error is exist (then i got FALSE as $image) and then I would like to stop script, but first I want to print an information about it.
Thanks.
回答1:
Fatal errors can't be muted or catched. You need to raise amount of memory allowed for PHP script by using memory_limit setting in php.ini
来源:https://stackoverflow.com/questions/46797422/php-fatal-error-is-any-way-to-not-stop-script