php mysql_pconnect(): 发送 5 个字节失败,errno=32 管道损坏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1894317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql_pconnect(): send of 5 bytes failed with errno=32 Broken pipe
提问by takeit
I've been using the same DB abstraction library for years. But today it started writing these Notice (8) messages in my log.
多年来,我一直在使用相同的 DB 抽象库。但是今天它开始在我的日志中写入这些通知 (8) 消息。
The application is working correctly but every time a script connects to the DB the same notice is logged.
应用程序工作正常,但每次脚本连接到数据库时都会记录相同的通知。
I cannot think what might have changed. This is happening on my local dev machine.
我想不出可能会发生什么变化。这发生在我的本地开发机器上。
OS X 10.6.2
PHP 5.3.0 (cli)
mysql Ver 14.12 Distrib 5.0.87
mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $
回答by takeit
If someone is struggling with this issue, here is the fix:
如果有人在这个问题上苦苦挣扎,这里是修复:
Try changing/setting up wait_timeoutin your mysql my.cnfconfig file:
尝试wait_timeout在您的 mysqlmy.cnf配置文件中更改/设置:
wait_timeout=3600
This config file is located in the /etc/mysql/my.cnf(Ubuntu/Debian) and /usr/local/mysql/my.cnf(OSX).
此配置文件位于/etc/mysql/my.cnf(Ubuntu/Debian) 和/usr/local/mysql/my.cnf(OSX) 中。
Restart mysql server and it should work.
重新启动 mysql 服务器,它应该可以工作。
回答by aesede
Only solution I've found so far is, changing
到目前为止我发现的唯一解决方案是改变
// From
PDO::ATTR_PERSISTENT => true
// To
PDO::ATTR_PERSISTENT => false
Not so happy with this, but works in the meantime. I'm using a very old PC for personal project, so I'm guessing the problem could have to do with lack of resources.
对此不太满意,但同时工作。我将一台非常旧的 PC 用于个人项目,所以我猜这个问题可能与缺乏资源有关。
回答by Anthony Rutledge
I am using PHP 5.6.20, PDO (throwing exceptions only), and MySQL 5.6.28 with persistent connections and EVERYTHING is utf8mb4. My entire stack is set up for utf-8 (dsn string settings, connections, database server databases, tables, columns, Apache 2.4.12, PHP, all webpages, CSS ... you name it).
我正在使用 PHP 5.6.20、PDO(仅抛出异常)和 MySQL 5.6.28 和持久连接,一切都是 utf8mb4。我的整个堆栈都是为 utf-8 设置的(dsn 字符串设置、连接、数据库服务器数据库、表格、列、Apache 2.4.12、PHP、所有网页、CSS ......你能说出它)。
I get the following error message intermittently and it is mystifying and annoying.
我间歇性地收到以下错误消息,这令人困惑和烦人。
Notice: PDO::__construct(): send of 5 bytes failed with errno=32 Broken pipe in file /foo/bar/baz
注意:PDO::__construct(): 发送 5 个字节失败,文件 /foo/bar/baz 中的 errno=32 Broken pipe
Assuming a persistent connectionis a noninteractiveone, the MySQL 5.6 manual (5.1.4 Server System Variables) says the following about the server system variable wait_timeout.
假设一个持续连接是一个非交互之一,MySQL的5.6手册(5.1.4服务器系统变量)表示有关服务器系统变量以下wait_timeout。
The number of seconds the server waits for activity on a noninteractiveconnection before closing it.
服务器在关闭非交互式连接之前等待活动的秒数 。
Default: 28800 sec
默认值:28800 秒
(28000 sec / 1) * (1 hour / 3600 sec) = 8 hours
(28000 sec / 1) * (1 hour / 3600 sec) = 8 hours
Max: 31536000 sec
最大:31536000 秒
((31536000 sec / 1) * (1 hr / 3600 sec) * (1 day / 24 hrs) = 365 days
Therefore, check wait_timeoutin your my.cnfand decide if persistent connections are what you need. Also, you'll have to invest in making your application more robust to account for a persistent connection that has been torn down.Clearly, you do not want your client to come back the next day (having gone home for the night) and say "What the heck?!"
因此,请检查wait_timeout您的my.cnf,并决定是否持久连接是你所需要的。此外,您必须投资使您的应用程序更加健壮,以解决已断开的持久连接。显然,您不希望您的客户第二天回来(回家过夜)并说“这到底是怎么回事?!”
回答by Lei Cao
It may be because your data contains 'utf-8' characters. I had the similar issue is caused by it.
可能是因为您的数据包含 'utf-8' 字符。我有类似的问题是由它引起的。
Exception: mysql_query(): send of 1462592 bytes failed with errno=32 Broken pipe
异常:mysql_query():发送 1462592 字节失败,errno=32 管道损坏
I used
我用了
mysql -u username -p database < dump_file # this is bad
to import the sql file contains lot of UTF8 characters (Thai language), but I didn't set default-character-set=utf8 for [mysql]. So the wrong coded data in the database caused that issue.
导入包含大量 UTF8 字符(泰语)的 sql 文件,但我没有为 [mysql] 设置 default-character-set=utf8。所以数据库中错误的编码数据导致了这个问题。
回答by Cioxideru
just remove mysqlnddriver and use mysqliYes mysqlndmore modern, but what about stability?
next commands fix your problem
只需删除mysqlnd驱动程序并使用mysqliYesmysqlnd更现代,但稳定性如何?下一个命令解决您的问题
apt-get remove php5-mysqlnd
apt-get install php5-pdo-mysql
apt-get 删除 php5-mysqlnd
apt-get 安装 php5-pdo-mysql

