[英]SQLSTATE[HY000]: General error: 2006 MySQL server has gone away magento
[英]SQLSTATE[HY000]: General error: 2006 MySQL server has gone away on running cron job magento
我正在Magento網站上工作,我收到此錯誤:
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away on running
cron job magento
我有時只會遇到這個錯誤。
<?php
class Namespace_Module_Model_Observer
{
public function importemails(Varien_Event_Observer $observer)
{
echo "Hi Dear";exit();
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myid@gmail.com';
$password = 'mypass';
/* try to connect */
$inbox = imap_open($hostname,$username,$password)
or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
/* output the email header information */
$output.=
'<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
/* close the connection */
imap_close($inbox);
}
}
此代碼可以工作幾個小時,然后它會出現此錯誤。 錯誤是什么意思?
數據庫連接有超時,如果您嘗試在打開連接后的某個時間發送查詢,將導致此錯誤。 通常的情況是:
那么 - 解決方案是什么? 您可以簡單地增加超時,但這很難看,並且當您網站的流量增加時可能會導致問題。 最好的解決方案是關閉數據庫連接,然后重新打開它,如下所示:
以下是更多信息: http : //dev.mysql.com/doc/refman/5.0/en/gone-away.html
如果您使用phpsh解釋器出現此錯誤。 我能夠用phpsh和一個新的shell來重現這個錯誤到doctrine manager。
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
在phpsh解釋器中使用此命令:
php> $result = $conn->query('select psetid from psetproblems')->fetchAll();
說明:
此錯誤是MySQL超時錯誤。 要么在創建連接之間等待太長時間,然后實際使用它,要么您使用其中一個命令出錯並且破壞了連接。 最簡單的解決方案是停止,重新啟動所有內容,不要運行拋出錯誤的命令,並快速執行。 它應該工作。
解
重啟你的口譯員。 不要通過解釋器提交錯誤並更快地發出命令。
您可以增加PHP的MySQL連接的超時長度。 然后,您可以在創建連接之間等待更長時間,然后再使用它。
我沒有任何超時問題。
我將一個fclose(STDERR)行從我的主文件移動到一個包含的文件,這開始發生了。
SQLSTATE [HY000]:一般錯誤:2006 MySQL服務器已經消失
我把線移回原來的位置,問題就消失了。
基本上,從包含文件關閉STDERR似乎有一些瘋狂的反響。
您還可以在使用共享主機時查看索引表大小。 它可能需要很多空間,因為你也可能得到“mysql服務器消失”。
我之前遇到過這個錯誤。 對於我的情況,這是由於數據庫大小太大,5年數據超過18gb。
對我有用的唯一解決方案是轉儲所有這些數據並創建一個新數據庫。
如果您有任何不使用Magento DB超過20秒的操作(我遇到了這樣的wait_timeout = 20的共享主機),您必須關閉數據庫連接。 Magento將在下次調用DB時創建新連接。
Mage::getSingleton('core/resource')->getConnection('read')->closeConnection();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.