duanjiuhong5843 2011-12-01 19:59
浏览 80
已采纳

确定PHP中超时的根本原因

A little while ago I noticed some Soap errors emitting from my app and I started to investigate them. Stuff like:

  • SoapClient::SoapClient(http://###.###.###.###:8080/path/to/some.wsdl): failed to open stream: HTTP request failed!
  • SoapClient::SoapClient(): I/O warning : failed to load external entity "http://###.###.###.###:8080/path/to/some.wsdl"
  • SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://###.###.###.###:8080/path/to/some.wsdl' : failed to load external entity "http://###.###.###.###:8080/path/to/some.wsdl"

It looked like a timeout on the remote server (WSDL caching was turned off). After bouncing that server and having no luck, I tried to just file_get-contents() the WSDL to see what would happen...

No dice: After about 20 seconds or so I got the same stream error:

file_get_contents(http://###.###.###.###:8080/path/to/some.wsdl) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed!

In a last ditch effort, I tried to read the contents via the curl_* functions, and I do in fact get what I'm looking for.

... tl;dr?

  • SoapClient and file_get_contents appear to be timing out (though not an explicit "Failed to open stream, connection timed out")
  • It appears to be related to streams since curl gives me what I'm looking for.
  • I've got a lot of code that depends on SoapClient and file_get_contents so switching to an all curl solution isn't really an option.
  • This is not a DNS issue as I can resolve external names fine (and my target resource is an IP)
  • allow_url_fopen is enabled.

Any ideas?

  • 写回答

1条回答 默认 最新

  • douyu7879 2011-12-01 20:03
    关注

    allow_url_fopen needs to be On in your PHP settings for file_get_contents to work with URLs. It'll give you that exact error otherwise. Double-check your PHP settings by loading a page with a phpinfo(); call to make sure they're not being overridden by a different php.ini or .htaccess file.

    I'd guess a firewall problem otherwise but you say curl works from inside PHP, which would be opening sockets in the same manner.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64