2013-05-08 53 views
0

我有一个Apache服务器,连接到MySQL数据库服务器。我得到了很多错误信息说:MySQL随机无法连接消息

PHP的警告:mysqli的:: mysqli的()(HY000/2003):无法连接到MySQL服务器上'10 .0.0.13'

但大多数情况下,连接没有问题,我可以在没有问题的情况下telnet 10.0.0.13 3306。我如何找出问题所在?

来源是php脚本,并且大部分时间它运行没有任何问题。这里是我如何连接:

error_reporting(E_ALL^E_NOTICE); 
ini_set('display_errors','On'); 
date_default_timezone_set ('Europe/Copenhagen'); 
Header('Content-type: text/xml'); 
$conn = new mysqli('10.0.0.13','webuser', 'xxxxxx', "np_indexes"); 

有什么建议吗?

此连接关闭是否正确?

$sql = "call spGetOrderDepthBySymbol('$stock', 0)"; 
    $result = $conn->query($sql); 
    while($row = $result->fetch_assoc()) { ?> 
     <row> 
      <type static="true"></type> 
      <shares flash="true"><?= $row['shares']<>"" ? number_format($row['shares'], 0, ',', '.') : '-' ?></shares> 
      <price flash="true"><?= $row['price']<>"" ? number_format($row['price'], 2, ',', '.') : '-' ?></price> 
     </row> 
    <? } 
    ?> 
    <spacer static="true"></spacer> 
    <? 
    $conn->next_result(); 
    $sql = "call spGetOrderDepthBySymbol('$stock', 1)"; 
    $result = $conn->query($sql); 
    while($row = $result->fetch_assoc()) { ?> 
     <row> 
      <type static="true"></type> 
      <shares flash="true"><?= $row['shares']<>"" ? number_format($row['shares'], 0, ',', '.') : '-' ?></shares> 
      <price flash="true"><?= $row['price']<>"" ? number_format($row['price'], 2, ',', '.') : '-' ?></price> 
     </row> 
    <? } 
    mysql_close($result); 
    ?> 
+0

是你的mysql运行?也许重启mysqld服务? – phpisuber01 2013-05-08 12:46:24

+1

可能存在连接限制。 – 2013-05-08 12:47:36

+0

您是否记得在完成后关闭连接?即使(特别是)当你的程序错误提前? – 2013-05-08 12:49:03

回答

0

也许这是你的情况。 see here

解说道:login as root and do setsebool -P httpd_can_network_connect=1

+0

虽然这个链接可能回答这个问题,但最好在这里包含答案的重要部分并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 – LittleBobbyTables 2013-05-08 13:23:49

+0

@LittleBobbyTables,对,我会编辑我的答案 – Amir 2013-05-08 13:27:00

+0

我认为,如果服务器拒绝来自网络的连接,错误将持续而不是随机的。 – KongUnold 2013-05-08 13:32:25

相关问题