問題描述
使用此代碼我發出肥皂請求
using this code I make soap requests
$client = new SoapClient('http://example.com/soap/wsdl');
try {
$result = $client->myMethod();
} catch (Exception $e) {
echo $e->getMessage();
}
有時(十分之一),會引發異常:
Sometimes (once out of ten), an exception is raised:
SoapFault 異常:[HTTP] 無法連接到主機
SoapFault exception: [HTTP] Could not connect to host
我的嘗試
1) 我尋找解決方案,我讀到這個問題可能是由 wsdl 緩存引起的,我在 php.ini
中禁用了它:
1) I looked for solutions, and I read that this problem can be caused by wsdl cache, I disabled it in php.ini
:
soap.wsdl_cache_enabled = 0
soap.wsdl_cache_ttl = 0
引發更少的異常
2) 我試圖將 windows/system32/drivers/etc/hosts
中 dns 的分辨率添加到 windows 主機(它們在 windows 上):
2) I tried to add to the host of windows (they are on windows) the resolution of the dns in windows/system32/drivers/etc/hosts
:
160.XX.XXX.XX example.com
引發更少的異常
3) 我也嘗試禁用Windows 防火墻",
3) I also tried to disable "Windows Firewall",
引發更少的異常
4) 我也嘗試增加 php.ini 中的 default_socket_timeout
4) I also tried to increase the default_socket_timeout in php.ini
default_socket_timeout = 90
什么都沒有改變
問題
服務器soap似乎沒有問題.從其他站點也可以正常使用.還有什么我可以做的嗎?
The server soap does not seem to have problems.It is used without problems also from other sites. Is there anything else I can do?
我的設置
PHP 5.6
阿帕奇 2.4
Windows Server 2012
Windows Server 2012
更新
經過多次測試,我認為問題出在網絡上,soap server后面有一個反向代理,問題出現在代理上.
After many tests, I think that the problem is in the network, soap server is behind a reverse proxy, the problem appears in the proxy.
推薦答案
您需要進一步改進調試工作:
You need to improve your debugging efforts even further:
ad 1) WSDL 變化很大嗎?如果沒有,打開 WSDL 緩存.您無需連接到服務器即可獲取 WSDL 文件.
ad 1) Does the WSDL change a lot? If not, turn on WSDL caching. You don't need to connect to the server to fetch the WSDL file.
你提到的輸出真的是在 echo $e->getMessage();
中創建的嗎?您可以在 catch()
塊中添加一些調試代碼,例如:
Is the output you mentioned really created in echo $e->getMessage();
? You could add some debugging code inside the catch()
block, for example:
- 檢查您是否可以通過其他方式連接到服務器(例如
file_get_contents($soap_url)
) - 如果沒有,請檢查您遇到的錯誤類型
- 打印時間并檢查 SOAP 服務器上的錯誤日志
- 一個 403 Forbidden 或類似服務器上的問題的錯誤點
- 無法連接錯誤指向網絡問題(并非唯一,但這種情況的可能性更高)
- check if you can connect to the server in another way (for example
file_get_contents($soap_url)
) - if not, check what kind of error you are getting
- print the time and check the error logs on the SOAP server
- a 403 Forbidden or similar error points on a problem on the server
- a Could not connect error points to a network problem (not exclusively but chances are higher for that)
總而言之,有時錯誤"很難調試,因此您要么應該嘗試使其可重現(這將指向問題),要么您需要記錄和輸出盡可能多的數據,以便您可以查看問題發生時的位置.
All in all, "sometimes errors" are hard to debug, so either you should try to make it reproducible (which will point at the problem), or you need to record and output as much data as possible so that you can see where the problem was at the time when it occurred.
這篇關于PHP SoapClient:SoapFault 異常無法連接到主機的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!