自從七步驟完成WordPress啟用SSL之http到https的最後一哩路跟繞地球一圈差不多and教學文賈奈!以來,小波飽受Fatal error: Out of memory之苦,之前沒仔細看設定說明,結果只是照著網路上看的方法改設定,結果仍難時不時就給我來一下Fatal error: Out of memory,先解放限制、八門全開看看吧。
解法ㄧ:修改php.ini
;;;;;;;;;;;;;;;;;;; ; Resource Limits ; ;;;;;;;;;;;;;;;;;;; ; 各PHP configuration參數詳細說明 ; 每個script的最長執行時間,預設300秒,註解掉並改max_input_time = 0即可無限 ; max_execution_time = 300 ; 每個script parse input data(如:POST and GET)的最長時間 max_input_time = 0 ; input variable的巢狀層級最大深度,預設64層 max_input_nesting_level = 102400 ; 限制GET/POST/COOKIE的input variables數,預設1000個 max_input_vars = 1000000 ; 每個script最多可花費的記憶體,預設128M,-1是無限 memory_limit= -1
全部都改超大,看Server會不會炸掉。
今天(2018/5/27)又發生Fatal error: Out of memory
只好再試試看
解法二:修改wp-config.php
參考WordPress.ORG: Increasing memory allocated to PHP
加入
define( 'WP_MAX_MEMORY_LIMIT', '10240M' );
Please note, this has to be put before wp-settings.php inclusion.
意思就是要加這那段程式碼之前才有效,那段程式碼長這樣
/** 設定 WordPress 變數和包含的檔案。 */ require_once(ABSPATH . 'wp-settings.php');
今天(2018/5/29)又發生Fatal error: Out of memory
因此解法一和二對我來說都無效
今天(2018/6/5)觀察到
當Apache超過1GB memory就會發生上述error,顯然以上設定都被無視。
解法三
.htaccess file以下地方加入語法
# BEGIN WordPress
<IfModule mod_rewrite.c>
(略)
</IfModule>
php_value memory_limit 10240M
再觀察看看吧
今天(2018/6/6)又發生Fatal error: Out of memory
難道是改錯.htaccess file? 之前都是改htdocs路徑下的.htaccess file,這次改htdocs/wordpress內的.htaccess file看看。
真正解法
改用x64的PHP和Apache(推薦用Bitnami)就再也不會Out of memory