2013-05-08 56 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

相關問題