dongqindan4406 2018-02-27 14:16
浏览 77
已采纳

启动多个PHP进程

So I have a script which does the following:

for ($i = $start;$i<=$end;$i++){
    shell_exec("php /home/mysql_box/script.php phrases $i {$argv[3]} > /dev/null 2>&1 &");
}

On one of my servers I would like this script to run 400 times. As part of the call it connects to a Mysql server on a different box but for some wierd reason hits about 130 connections and then errors saying "Mysql server has gone away".

I appreciate this is quite common and the MySQL manual states:

You can also encounter this error with applications that fork child processes, all of which try to use the same connection to the MySQL server. This can be avoided by using a separate connection for each child process.

However I wouldn't be using the same connection surely? My wait_timeout is the default - but huge so why would some connections simply not be able to connect?

A couple of other points from the manual:

  1. The connection uses the IP not host name
  2. I didn't start mysql with skip-networking
  3. The query is a single one liner - its not big
  4. I am using Ubuntu
  5. I am connecting with PDO

I hope I've given enough info to help.

  • 写回答

3条回答 默认 最新

  • duandu1966 2018-03-22 09:31
    关注

    So I believe I have discovered the issue and I hope this helps anyone else. The reason being was that the initial query that was run on each loop took aprox 15 seconds. For some reason this reduced the amount of concurrent new connections and as such crashed out. The solution was to therefore reduce the query time required and so if you experience this problem as well - play around with the queries themselves.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘