突然“MySQL服务器已经消失” PHP网站错误 [英] Sudden "MySQL server has gone away" error in PHP site

查看:149
本文介绍了突然“MySQL服务器已经消失” PHP网站错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我的一个网站开始显示

错误号码:2006 
MySQL服务器已经消失

这是一个在Apache 2.2.9(Debian),PHP 5.2.6-1 + lenny3(使用CodeIgniter 1.7.1框架)和MySQL 5.0.51a下运行的低流量客户端站点。我显然重申了错误,但是所有可能的解决方案都意味着有很大的查询可能会超时并重置连接,或者达到数据包限制。但是,情况并非如此,它是用最简单的查询处理的小数据库。为了确保这一点,我组成了一些查询返回一行,仍然是一样的错误。



数据库凭据很好,我甚至可以直接登录到mysql,运行一些网站的查询并立即获得正确的数据。在同一台服务器上还有其他几个站点和数据库连接,更大的网站,并且都没有问题。



我试过:




  • 重新启动MySQL

  • 重新启动整个服务器

  • 寻找日志中的错误(Apache和MySQL都没有)

  • 检查数据库用户权限

  • 更改 mysql.connect_timeout default_socket_timeout 在PHP

  • 在MySQL中更改 max_allowed_pa​​cket

  • 阅读官方文档 ,论坛和SO中的所有内容都表示MySQL服务器已经消失



新建




  • 在PHP中禁用持久连接

  • 更改 wait_timeout connect_timeout 在MySQL



更新: / p>

这似乎与我的脚本的执行时间有关:它使用Facebook PHP客户端检索一些信息,这个调用似乎在今天随机失败,所以我没有Facebook的数据或MySQL错误。但令我惊讶的是,没有一个给定的解决方案似乎处理超时。



任何想法?谢谢你的时间!

解决方案

正如我在更新中所说,我的结论是,MySQL的问题出现在Facebook需要的时间长于DB的最大连接时间。没有一个建议可以击败这个限制,所以我决定解决它,并重新连接每次我推测链接可能会消失。



所以每次调用Facebook后,我以下代码:

 $ this-> load-> database(); 
$ this-> db-> reconnect();

这是使用CodeIgniter和AFAIK db-> reconnect( )功能只能从版本1.7.2开始,所以我更新了它才能工作。



感谢大家的答案!


Today one of my websites started showing

Error Number: 2006
MySQL server has gone away

It's a low-traffic client site running under Apache 2.2.9 (Debian), PHP 5.2.6-1+lenny3 (using CodeIgniter 1.7.1 framework) and MySQL 5.0.51a. I obviously reasearched about the error but all the possible solutions imply that there are big queries going on that may time out and reset the connection, or hit the packet limits. However, this is not the case, it's a small database processed with the simplest queries. To be sure about this I made up a few queries to return one row, still the same error.

Database credentials are fine, I can even login directly into mysql, run some of the site's queries and get the right data instantly. There are several other sites on the same server and connections to the database, much larger sites, and they all have no problems.

I tried:

  • Restarting MySQL
  • Restarting the whole server
  • Looking for errors in the logs (both Apache and MySQL, none)
  • Checking db user permissions
  • Changing mysql.connect_timeout and default_socket_timeout in PHP
  • Changing max_allowed_packet in MySQL
  • Reading the official docs, forum and everything in SO that says "MySQL server has gone away"

New:

  • Disabling persistent connections in PHP
  • Changing wait_timeout and connect_timeout in MySQL

Update:

It seems to be related to the execution time of my script: it retrieves some info using the Facebook PHP client and this call seems to be failing randomly today, so I either have no data from Facebook or the MySQL error. But to my surprise, none of the given solutions seems to deal with the timeout.

Any ideas? thank you for your time!

解决方案

As I said in my update, I concluded that the problem with MySQL arises when the link to Facebook takes longer than the maximum connection time with the DB. None of the suggestions could beat this limitation, so I decided to work around it and reconnect every time I presumed the link maybe gone.

So after each call to Facebook, I used to following code:

$this->load->database();
$this->db->reconnect();

This is the particular solution when using CodeIgniter, and AFAIK the db->reconnect() function is only available since version 1.7.2 so I updated it in order to work.

Thanks everyone for your answers!

这篇关于突然“MySQL服务器已经消失” PHP网站错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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