2010-01-11

【系統】PHP - Fatal error: Allowed memory size of xxx bytes exhausted

上禮拜程式執行時,居然出現這樣的錯誤訊息。

字面上看起來應該就是 Memory 的問題了。

所以解決的方法就是到 php.ini 將 memory_limit 加大。

# vi /php-etc-path/php.ini

將 memory_limit 改成

memory_limit = 128M

但數字是看各程式的需求。

另外也可以直接在程式中設定,但記得要放在整個程式的前面。

ini_set("memory_limit","128M");
?>

PS. 另外還有其他的設定
  ini_set("max_execution_time",300000);
  ini_set("max_input_time",600000);

補充說明 memory_limit : ( PHP Configuration )


memory_limit

The Memory section of the Official Requirements part of this document provides some sample values. After you consult the memory table you may decide on 12M as the correct value. You would then edit your php.ini with this value.

memory_limit = 12M

Trial and error may be required to find the right value depending on the limitations of your phpWebSite installation environment. As noted in the memory table the number of modules that you Boost with the core phpWebSite system will greatly affect how this parameter should be set. If the value in the memory_limit parameter is set too low, then you will receive fatal runtime error messages

Fatal error: Allowed memory size of m bytes exhausted (tried to allocate e bytes) in Unknown on line n

* where m is the the memory limit the was exhausted.
* where e is the number of bytes that the memory limit was exceed by.
* where n is the line number in the phpWebSite system code where the php memory limit setting was exhausted.

以上~

0 comments:

張貼留言