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

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

问题描述

我的网站之一开始显示

Error Number: 2006
MySQL server has gone away

这是一个运行在Apache 2.2.9(Debian),PHP 5.2.6-1 + lenny3(使用CodeIgniter 1.7.1框架)和MySQL 5.0.51a的低流量客户端。我显然重新解决了错误,但所有可能的解决方案暗示有大量的查询,可能超时和重置连接,或命中数据包限制。然而,情况并非如此,它是一个用最简单的查询处理的小数据库。为了确保这一点我做了几个查询返回一行,仍然是一样的错误。

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.

数据库凭据是好的,我甚至可以直接登录mysql,运行部分网站的查询,并即时获得正确的数据。在同一个服务器上有几个其他网站,连接到数据库,更大的网站,他们都没有问题。

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.

我试过:


  • 重新启动MySQL

  • 重新启动整个服务器

  • 在日志中查找错误(Apache和MySQL,无)

  • 检查数据库用户权限

  • 更改 mysql.connect_timeout
  • 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"

新功能:


  • 在PHP中停用持续连接

  • 更改 wait_timeout connect_timeout 在MySQL中

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

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

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!

推荐答案

正如我在更新中所说,我的结论是MySQL的问题出现时, Facebook比与数据库的最大连接时间长。没有任何建议可以击败这个限制,所以我决定解决它,并重新连接每次我假设链接可能走了。

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.

因此,每次调用Facebook后,我用于以下代码:

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

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

这是使用CodeIgniter时的特定解决方案,AFAIK db-> reconnect )函数只有从1.7.2版本可用,所以我更新它为了工作。

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.

感谢大家的答案!

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

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