PHP - Fatal Error - is any way to not stop script? [duplicate]

巧了我就是萌 提交于 2020-01-16 10:12:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!