iT邦幫忙

0

wordpress 記憶體不足

先說我已經上網看過好幾篇文章的教學,我都試過各種改記憶體限制大小的方法了
但是問題仍然相同。
我的系統環境是
Windows Server
XAMPP
架設的,實體的記憶體很夠但是不知道為什麼會一直出現記憶體不足
Fatal error: Out of memory (allocated 2097152) (tried to allocate 458752 bytes) in
這樣之類的
求各位大大了

補充試過的方法有
1.wp-config.php 裡新增
define('WP_MEMORY_LIMIT', '256M'); 後來改512M也不行
2.php.ini 裡修改
memory_limit = 256M 後來改512M也不行
3.甚至我也改了 PHP上傳檔案的限制
max_execution_time
max_input_time
post_max_size
upload_max_filesize
default_socket_timeout
mysql.connect_timeout
這幾個參數
4.我也有到wp-includes目錄下的default-constants.php 更改數值 我最後還改到800

if ( ! defined( 'WP_MEMORY_LIMIT' ) ) {
	if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
		define( 'WP_MEMORY_LIMIT', $current_limit );
	} elseif ( is_multisite() ) {
		define( 'WP_MEMORY_LIMIT', '800M' );
	} else {
		define( 'WP_MEMORY_LIMIT', '800M' );
	}
}

if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
	if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
		define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
	} elseif ( -1 === $current_limit_int || $current_limit_int > 838860800 /* = 800M */ ) {
		define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
	} else {
		define( 'WP_MAX_MEMORY_LIMIT', '800M' );
	}
}
看更多先前的討論...收起先前的討論...
fillano iT邦超人 1 級 ‧ 2017-11-26 16:58:21 檢舉
改一下php.ini,裡面有記憶體限制。你找一下memory_limit這個設定,看看原本是多少。
fillano iT邦超人 1 級 ‧ 2017-11-26 17:07:35 檢舉
2097152 bytes也就是2M...

另外,為了避免我們猜測你試過的方法,可以說一下你試過哪些方法嗎?
d2598798 iT邦新手 5 級 ‧ 2017-11-26 18:30:26 檢舉
memory_limit 我已經改過了 改到256M
d2598798 iT邦新手 5 級 ‧ 2017-11-26 18:30:46 檢舉
原本我記得是128M
weiclin iT邦高手 4 級 ‧ 2017-11-26 19:18:11 檢舉
https://wordpress.org/plugins/php-settings/
用這個看一下你改過的設定是不是有生效
d2598798 iT邦新手 5 級 ‧ 2017-11-26 19:51:40 檢舉
能幫我看有哪些問題嗎? >< 記憶體限制的部分都有修改
PHP Version 7.1.9
allow_url_fopen On
allow_url_include Off
arg_separator.input &
arg_separator.output &
auto_append_file no value
auto_globals_jit On
auto_prepend_file no value
browscap C:\xampp\php\extras\browscap.ini
default_charset UTF-8
default_mimetype text/html
disable_classes no value
disable_functions no value
display_errors On
display_startup_errors On
doc_root no value
docref_ext no value
docref_root no value
enable_dl Off
enable_post_data_reading On
error_append_string no value
error_log C:\xampp\php\logs\php_error_log
error_prepend_string no value
error_reporting 4983 Locally Overridden
expose_php On
extension_dir C:\xampp\php\ext
file_uploads On
hard_timeout 2
highlight.comment #FF8000
highlight.default #0000BB
highlight.html #000000
highlight.keyword #007700
highlight.string #DD0000
html_errors On
ignore_repeated_errors Off
ignore_repeated_source Off
ignore_user_abort Off
implicit_flush Off
include_path C:\xampp\php\PEAR
input_encoding no value
internal_encoding no value
log_errors On
log_errors_max_len 1024
mail.add_x_header On
mail.force_extra_parameters no value
mail.log no value
max_execution_time 300
max_file_uploads 20
max_input_nesting_level 64
max_input_time 300
max_input_vars 1000
memory_limit 800M
open_basedir no value
output_buffering 4096
output_encoding no value
output_handler no value
post_max_size 200M
precision 14
realpath_cache_size 4096K
realpath_cache_ttl 120
register_argc_argv Off
report_memleaks On
report_zend_debug On
request_order GP
sendmail_from no value
sendmail_path no value
serialize_precision -1
short_open_tag Off
SMTP localhost
smtp_port 25
sql.safe_mode Off
sys_temp_dir no value
track_errors Off
unserialize_callback_func no value
upload_max_filesize 200M
upload_tmp_dir C:\xampp\tmp
user_dir no value
user_ini.cache_ttl 300
user_ini.filename .user.ini
variables_order GPCS
windows.show_crt_warning Off
xmlrpc_error_number 0
xmlrpc_errors Off
zend.assertions 1
zend.detect_unicode On
zend.enable_gc On
zend.multibyte Off
zend.script_encoding no value
weiclin iT邦高手 4 級 ‧ 2017-11-27 08:16:36 檢舉
這樣還是記憶體不足嗎? 錯誤訊息長怎樣?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
bizpro
iT邦大師 1 級 ‧ 2017-11-27 10:35:16
最佳解答

記憶體不足:

  1. Apache, PHP-FPM, Wordpress設定不足: 已排除
  2. Wordpress某些插件耗用太多記憶體: 請查, 如停用所有插件試試.
  3. 資料庫耗用太多記憶體.
  4. 如果是託管在雲端, 請查是否有限制.
看更多先前的回應...收起先前的回應...
d2598798 iT邦新手 5 級 ‧ 2017-11-27 13:59:28 檢舉

資料庫的記憶體能否調整呢?

d2598798 iT邦新手 5 級 ‧ 2017-11-27 14:17:17 檢舉

https://ithelp.ithome.com.tw/upload/images/20171127/201030616BCYi07wMW.png

https://ithelp.ithome.com.tw/upload/images/20171127/20103061WPLEPvQ8Ub.png

我的外掛應該都還好吧

d2598798 iT邦新手 5 級 ‧ 2017-11-27 15:03:02 檢舉

全部插件關掉 就不會出現記憶體不足了
可是問題是那些插件我都需要阿..
我是自己架設的,阿帕契記憶體用很兇每次記憶體使用到2.9G的時候網站就很容易出現記憶體不足 可是我實體記憶體有4G
然後不知道正不正常 真的會用到2G多嗎?

bizpro iT邦大師 1 級 ‧ 2017-11-27 20:52:58 檢舉
d2598798 iT邦新手 5 級 ‧ 2017-11-28 16:21:54 檢舉

實體記憶體有4G,阿帕契每次記憶體使用到2.9G就很容易出現記憶體不足
這就是解答,請再增加你的實體記憶體,還有你應該是 64位元的OS吧

d2598798 iT邦新手 5 級 ‧ 2017-11-29 18:33:10 檢舉

我主機總記憶體是24G 4G是VMware分配的實體記憶體 我試過分配6G 也沒有用 到2.9G 或有時候2.5G 就會出現Out of memory,我作業系統是64位元沒錯,然後我有注意看當我發一篇字數和媒體檔案較多的文章按發布的一瞬間 記憶體會飆到3G 然後順間又掉到1G多,然後就會出現Out of memory。
連續上傳媒體檔案的圖片檔也會Out of memory
現在我已經把網站資料轉移虛擬主機就沒發生了。

bizpro iT邦大師 1 級 ‧ 2017-11-30 22:05:07 檢舉

所以您的真實問題是出現在上傳檔案上. 以下是基本觀念:
用HTTP上傳檔案, Apache會交給PHP腳本進行上傳, 所有的上傳資料都在記憶體中, 因此, 記憶體用量會飆高. PHP沒有足夠的記憶體就會發生錯誤. 那這是誰的問題? Apache!. Apache是程序式(process-based)伺服器, 如果您在同一個程序中塞入一堆資料進記憶體, 就有機會不夠. 建議使用事件式(event-based)伺服器, 如Nginx.

d2598798 iT邦新手 5 級 ‧ 2017-12-02 11:52:52 檢舉

謝謝大師的講解,但是是不是因為Apache是32位元所以每次只能使用到3G多? 我就算有6G 也會記憶體不足

bizpro iT邦大師 1 級 ‧ 2017-12-02 13:40:20 檢舉

您的Apache是32位元? 其他的實體記憶體都是看不到的.
巧婦難為無米之炊

我要發表回答

立即登入回答