SQLSTATE [HY000]:常规错误:2006 MySQL服务器在运行cron作业magento时已消失 [英] SQLSTATE[HY000]: General error: 2006 MySQL server has gone away on running cron job magento

查看:101
本文介绍了SQLSTATE [HY000]:常规错误:2006 MySQL服务器在运行cron作业magento时已消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Magento网站上工作,但出现此错误:

I am working on Magento site and I get this error:

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away on running 
cron job magento

有时我只会收到此错误.

I only get this error sometimes.

<?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);
  }  
}

此代码可以工作几个小时,然后出现此错误.错误是什么意思?

This code works for several hours then it gives this error. What does the error mean?

推荐答案

DB连接超时,如果您在打开连接后的某个时间尝试发送查询,则会导致此错误.通常的情况是:

DB Connections have a timeout which will cause this error if you try to send a query sometime after opening the connection. The usual scenario is:

  • 打开数据库连接
  • 从数据库中获取一些数据
  • 做事,例如发送电子邮件(花费的时间比数据库连接超时长)
  • 使用相同的连接查询数据库
  • 错误:MySQL服务器已消失

那么-解决方案是什么?您可以简单地增加超时时间,但这很丑陋,并且在访问您的网站的流量增加时可能会引起问题.最好的解决方案是关闭数据库连接,然后像这样重新打开它:

So - what's the solution? You could simply increase the timeout, but that's ugly and could cause problems when traffic to your site increases. The best solution would be to close your DB connection and then re-open it like this:

  • 打开数据库连接
  • 从数据库中获取一些数据
  • 关闭数据库连接
  • 做事,例如发送电子邮件(花费的时间比数据库连接超时长)
  • 打开新的数据库连接
  • 使用相同的连接查询数据库
  • 关闭数据库连接

更多信息: http://dev.mysql.com/doc/refman/5.0/en/gone- away.html

这篇关于SQLSTATE [HY000]:常规错误:2006 MySQL服务器在运行cron作业magento时已消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆