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 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?