Sql-Server

FreeTDS PHP mssql_connect() 503 刷新

  • October 24, 2016

我們最近在我們的一台 RHEL7 伺服器上安裝了帶有 php56-mssql 的 FreeTDS。除了這個奇怪的問題外,一切似乎都正常執行。我們第一次載入使用 mssql_connect() 函式的 php 頁面時,該頁面訪問 sql server 2012 實例,獲取數據並按預期呈現頁面。但是,如果我們刷新頁面一次,頁面將呈現,但沒有來自數據庫的任何數據。如果我們再次刷新,我們會收到以下 503 消息:

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

如果我們繼續第三次刷新,頁面將按預期呈現所有數據。同樣在故障排除過程中,我注意到如果我們載入頁面,等待大約 15 秒,然後刷新,頁面會按預期載入。

瀏覽 error_log 時,我們會看到以下消息:

[Fri Oct 21 12:37:44.971872 2016] [proxy_fcgi:error] [pid 14052:tid 140504888997632] [client xx.xxx.xx.xx:xxxxx] AH01071: Got error 'PHP message: PHP Warning:  mssql_select_db(): 2 is not a valid MS SQL-Link resource in /var/www/vhosts/example.com/e0/conn.php on line 6\nPHP message: PHP Warning:  mssql_init(): 2 is not a valid MS SQL-Link resource in /var/www/vhosts/example.com/httpdocs/e1/search.php on line 16\nPHP message: PHP Warning:  mssql_bind() expects parameter 1 to be resource, boolean given in /var/www/vhosts/example.com/httpdocs/e1/search.php on line 17\nPHP message: PHP Warning:  mssql_bind() expects parameter 1 to be resource, boolean given in /var/www/vhosts/example.com/httpdocs/e1/search.php on line 18\nPHP message: PHP Warning:  mssql_execute() expects parameter 1 to be resource, boolean given in /var/www/vhosts/example.com/httpdocs/e1/search.php on line 19\nPHP message: PHP Warning:  mssql_free_statement() expects parameter 1 to be resource, boolean given in /var/www/vhosts/example.com/httpdocs/e1/search.php on line 20\nPHP message: PHP Warning:  mssql_fetch_array() expects parameter 1 to be resource, null given in /var/www/vhosts/example.com/httpdocs/e1/search.php on line 23\nPHP message: PHP Notice:  Undefined offset: 0 in /var/www/vhosts/example.com/httpdocs/e1/search.php on line 53\nPHP message: PHP Notice:  Undefined offset: 0 in /var/www/vhosts/example.com/httpdocs/e1/search.php on line 60\n', referer: http://example.com/contacts/
[Fri Oct 21 12:37:45.347450 2016] [proxy_fcgi:error] [pid 14109:tid 140504956139264] (104)Connection reset by peer: [client xx.xxx.xx.xx:xxxxx] AH01075: Error dispatching request to :, referer: http://example.com/e1/
[Fri Oct 21 12:37:45.347625 2016] [include:warn] [pid 14109:tid 140504956139264] [client xx.xxx.xx.xx:xxxxx] AH01374: mod_include: Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed: /error_docs/maintenance.html, referer: http://example.com/e1/

有什麼建議麼?我不知道為什麼會以這種方式發生!?

更新

使用此連接測試了另一個頁面。它第一次載入很好,但是如果您在 15 秒之前再次請求它,它直接無法連接:

AH01071: Got error 'PHP message: PHP Warning:  mssql_connect(): Unable to connect to server: theServerName

在這種情況下,問題恰好是我們的新伺服器被設置為將此應用程序作為“Apache 服務的 FPM 應用程序”執行,而我們應該將此應用程序設置為“Apache 服務的 FastCGI 應用程序”執行。

引用自:https://serverfault.com/questions/810536