咨询关于mysql_connect超时连接

lxp642 2014-12-19 10:34:22
烦请各位提供思路,分析可能存在的问题

连接代码,以下简化的生产代码
$start_time = date('Y-m-d H:i:s');
if(mysql_connect($config['dbhost'], $config['dbuser'], $config['dbpw'], TRUE)){
// something code
}else{
error_log('['. date('Y-m-d H:i:s') .'] 连接失败'.$this->error().' start='.$start_time.' host='.$config['dbhost'].' user='.$config['dbuser']."\n", 3, UC_ROOT.'logs/sqlerr_'.date('Y-m-d').'.log');
}
连接超时日志,有个规律是7秒这个值
[2014-12-17 21:10:37] 连接失败Connection timed out start=2014-12-17 21:10:30 host=192.168.1.6:3306 user=cuser
[2014-12-17 21:11:15] 连接失败Connection timed out start=2014-12-17 21:11:08 host=192.168.1.6:3306 user=cuser
[2014-12-17 21:16:35] 连接失败Connection timed out start=2014-12-17 21:16:28 host=192.168.1.6:3306 user=cuser
[2014-12-17 21:34:55] 连接失败Connection timed out start=2014-12-17 21:34:48 host=192.168.1.6:3306 user=cuser
[2014-12-17 21:46:55] 连接失败Connection timed out start=2014-12-17 21:46:48 host=192.168.1.6:3306 user=cuser
[2014-12-17 21:47:24] 连接失败Connection timed out start=2014-12-17 21:47:17 host=192.168.1.6:3306 user=cuser
[2014-12-17 22:15:28] 连接失败Connection timed out start=2014-12-17 22:15:21 host=192.168.1.6:3306 user=cuser
[2014-12-17 22:38:20] 连接失败Connection timed out start=2014-12-17 22:38:13 host=192.168.1.6:3306 user=cuser
[2014-12-17 22:38:54] 连接失败Connection timed out start=2014-12-17 22:38:47 host=192.168.1.6:3306 user=cuser
[2014-12-17 22:39:41] 连接失败Connection timed out start=2014-12-17 22:39:34 host=192.168.1.6:3306 user=cuser
[2014-12-17 22:52:20] 连接失败Connection timed out start=2014-12-17 22:52:13 host=192.168.1.6:3306 user=cuser
[2014-12-17 23:21:54] 连接失败Connection timed out start=2014-12-17 23:21:47 host=192.168.1.6:3306 user=cuser


以下为部分长ping数据
PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.
64 bytes from 192.168.1.6: icmp_seq=1 ttl=64 time=0.158 ms
64 bytes from 192.168.1.6: icmp_seq=2 ttl=64 time=0.142 ms
64 bytes from 192.168.1.6: icmp_seq=3 ttl=64 time=0.153 ms
64 bytes from 192.168.1.6: icmp_seq=4 ttl=64 time=0.137 ms
64 bytes from 192.168.1.6: icmp_seq=5 ttl=64 time=0.203 ms
64 bytes from 192.168.1.6: icmp_seq=6 ttl=64 time=0.150 ms
64 bytes from 192.168.1.6: icmp_seq=7 ttl=64 time=0.139 ms
64 bytes from 192.168.1.6: icmp_seq=8 ttl=64 time=0.137 ms
64 bytes from 192.168.1.6: icmp_seq=9 ttl=64 time=0.201 ms

以下为部分php.ini部分参数设置信息
php.ini
max_execution_time = 30
max_input_time = 60
default_socket_timeout = 60
mysql.connect_timeout => 60 => 60
default_socket_timeout => 60 => 60

...全文
140 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxp642 2014-12-22
  • 打赏
  • 举报
回复
这个地方这么不活跃?
猪崽儿0o0 2014-12-19
  • 打赏
  • 举报
回复
引用 2 楼 lxp642 的回复:
[quote=引用 1 楼 u011619326 的回复:] 你是想链接远程的?那你需要给你目前的IP赋予权限或者你直接把MYSQL的权限全部放开都可以。
您好,不是权限问题,超时仅仅部分连接~[/quote]你用try catch 抓取下看下详细报错看看。
lxp642 2014-12-19
  • 打赏
  • 举报
回复
引用 1 楼 u011619326 的回复:
你是想链接远程的?那你需要给你目前的IP赋予权限或者你直接把MYSQL的权限全部放开都可以。
您好,不是权限问题,超时仅仅部分连接~
猪崽儿0o0 2014-12-19
  • 打赏
  • 举报
回复
你是想链接远程的?那你需要给你目前的IP赋予权限或者你直接把MYSQL的权限全部放开都可以。

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧