我最近在我的WordPress網站上注意到我有時會收到500內部服務器錯誤。我檢查日誌,我有很多線,如:WordPress致命錯誤:允許的內存大小536870912字節耗盡(試圖分配77字節)在wp-includes/wp-db.php上線1832
[Mon Oct 03 01:25:24.357439 2016] [fcgid:warn] [pid 12840] [client 83.27.211.107:36968] mod_fcgid: stderr: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 77 bytes) in /var/www/vhosts/mywebsite/public_html/wp-includes/wp-db.php on line 1832
我試圖增加內存限制:
define('WP_MAX_MEMORY_LIMIT' , '512M');
define('WP_MEMORY_LIMIT' , '512M');
甚至更多,但沒有奏效。無論我如何設置它仍然超過內存限制一些字節。我認爲對數據庫的某些查詢存在問題,但如何檢查哪些?
內容的包括/可溼性粉劑db.php中的:
} else {
$num_rows = 0;
if ($this->use_mysqli && $this->result instanceof mysqli_result) {
while ($row = mysqli_fetch_object($this->result)) {
$this->last_result[$num_rows] = $row;
$num_rows++;
}
} elseif (is_resource($this->result)) {
// server crashing at line below
while ($row = mysql_fetch_object($this->result)) {
$this->last_result[$num_rows] = $row;
$num_rows++;
}
}
// Log number of rows the query returned
// and return number of rows selected
$this->num_rows = $num_rows;
$return_val = $num_rows;
}
所以問問自己**爲什麼**你需要在RAM中緩存500 + megs的數據。如果你需要,那麼你的選擇是提高/刪除內存限制,或重建你的系統,所以你不需要同時在內存中那麼多東西。否則,你基本上會問:「我把10升水倒進一個1升的水桶裏,水溢出了,我怎麼能讓它溢出來?」 –
您自己的服務器或虛擬主機? – markratledge
@MarcB,你不明白。我在我的網站上有一個錯誤。這是簡單的WordPress網站,5個小部件,菜單和帖子循環(每頁20個)。我不知道爲什麼這個超過內存的限制。 –