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


i working on magento site , error:

sqlstate[hy000]: general error: 2006 mysql server has gone away on running  cron job magento 

i error sometimes.

<?php class namespace_module_model_observer  {   public function importemails(varien_event_observer $observer)   {     echo "hi dear";exit();      /* connect gmail */     $hostname = '{imap.gmail.com:993/imap/ssl}inbox';     $username = 'myid@gmail.com';     $password = 'mypass';      /* try connect */     $inbox = imap_open($hostname,$username,$password)          or die('cannot connect gmail: ' . imap_last_error());      /* grab emails */     $emails = imap_search($inbox,'all');      /* if emails returned, cycle through each... */     if($emails) {        /* begin output var */       $output = '';        /* put newest emails on top */       rsort($emails);        /* every email... */       foreach($emails $email_number) {          /* information specific email */         $overview = imap_fetch_overview($inbox,$email_number,0);         $message = imap_fetchbody($inbox,$email_number,2);          /* output 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 email body */         $output.= '<div class="body">'.$message.'</div>';       }       echo $output;     }       /* close connection */     imap_close($inbox);   }   } 

this code works several hours gives error. error mean?

db connections have timeout cause error if try send query sometime after opening connection. usual scenario is:

  • open db connection
  • fetch data db
  • do stuff, e.g. send emails (takes time longer db connection timeout)
  • query db using same connection
  • error: mysql server has gone away

so - what's solution? increase timeout, that's ugly , cause problems when traffic site increases. best solution close db connection , re-open this:

  • open db connection
  • fetch data db
  • close db connection
  • do stuff, e.g. send emails (takes time longer db connection timeout)
  • open new db connection
  • query db using same connection
  • close db connection

here's more information: http://dev.mysql.com/doc/refman/5.0/en/gone-away.html


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -