doukong1901 2014-01-14 18:01
浏览 301

mysqli_connect()突然非常慢

I have not changed anything in this situation recently, but recently my mysqli_connect() to a remote server is very slow (about half the time it hits the 30 second max execution time). When it works, the response time is between 28 and 30 seconds.

I have restarted MySQL on both servers. The server holding the PHP script is a local WAMP server, the remote server is a LAMP stack. The LAMP server performs fine serving the same information that the WAMP server is requesting. The queries do not appear to be the issue, instead it looks like mysqli_connect() is the problem:

    $mtime = microtime(); 
    $mtime = explode(" ",$mtime); 
    $starttime = $mtime[1] + $mtime[0]; 
        $this->conn = mysqli_connect($this->host,$this->user,$this->password) or die(mysqli_error($this->conn));
        $etime = microtime(); 
    $etime = explode(" ",$etime); 
    $endtime = $etime[1] + $etime[0]; 
    $totaltime = ($endtime - $starttime);  
    echo('<!--mysqli_connect took: '.$totaltime.' seconds-->');

The page (when it does not give a 500 response for hitting max_execution_time) will show:

<!--mysqli_connect took: 28.975151777267 seconds-->

The same code on the remote LAMP server will show:

<!--mysqli_connect took: 0.036190032958984 seconds-->

I have not updated this code or made any configuration changes since this was working. I get no errors on either server except for the max_execution_time exceeded error when it goes past 30 seconds on the WAMP server. Does anyone have any suggestions?

Thanks for reading.

  • 写回答

2条回答 默认 最新

  • dpvr49226 2014-01-14 18:09
    关注

    Perhaps a DNS issue? Have you tried changing your host string to a straight IP address rather than say a domain? There was a similar question here, Connecting to mysql server(localhost) very slow , that sounded similar however it was local host and changing to 127.0.0.1 fixed the issue.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line