PHP MySQL数据库连接保持活动状态多长时间? [英] How long does a PHP MySQL database connection remain active?

查看:413
本文介绍了PHP MySQL数据库连接保持活动状态多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行时间较长的PHP脚本.我正在脚本的最开始进行数据库连接,并在启动时进行了一些数据库操作.

I have a long running PHP script. I am making the database connection at the very beginning of the script and does some database operation at the start up.

此后,脚本执行了4个小时的PHP操作,即使一次也没有通过该连接ping通MySQL.

After that, the script perform 4 hours of PHP operation without pinging to MySQL with that connection even a single time.

在这些长时间运行的PHP操作结束时,当我尝试执行mysql_query时,出现以下错误:MySQL Server has gone Away

At the end of these long running PHP operations, when I try to execute mysql_query it gives me the following error: MySQL Server has gone Away

是否有可能将连接超时增加到4小时?我正在使用PHP ADODB从我的PHP应用程序与MySQL连接.

Is there any possibility of increasing the connection timeout to be 4 hours? I am using PHP ADODB to connect with MySQL from my PHP application.

请提出建议?

推荐答案

MySQL的超时不同于PHP.您可以在php.ini行的mysql.connect_timeout = 14400中增加它.同时增加default_socket_timeout = 14400

MySQL has a different timeout than PHP. You could increase it in php.ini on the line mysql.connect_timeout = 14400. Also increase the default_socket_timeout = 14400

请注意,如果您的PHP设置允许您执行ini_set,则还可以执行以下操作:

Note that if your PHP setting allow you to do an ini_set, you can also do as follows:

ini_set('mysql.connect_timeout', 14400);
ini_set('default_socket_timeout', 14400);

这篇关于PHP MySQL数据库连接保持活动状态多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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