确定 PHP 超时的根本原因

发布于 2024-12-19 02:50:11 字数 1198 浏览 0 评论 0原文

不久前,我注意到我的应用程序发出了一些 Soap 错误,我开始调查它们。像这样的东西:

  • SoapClient::SoapClient(http://###.###.###.###:8080/path/to/some.wsdl): 无法打开流: HTTP 请求失败!
  • SoapClient::SoapClient(): I/O 警告:无法加载外部实体“http://###.###.###.###:8080/path/to/some.wsdl”
  • SOAP-错误:正在解析 WSDL:无法从以下位置加载'http://###.###.###.###:8080/path/to/some.wsdl':无法加载外部实体“http://###.###.###.###:8080/path/to/some.wsdl”

看起来远程服务器超时(WSDL 缓存已关闭) )。在退回该服务器但没有运气之后,我尝试使用 file_get-contents() WSDL 来看看会发生什么...

没有骰子:大约 20 秒后,我得到了相同的流错误:

file_get_contents(http://###.###.###.###:8080/path/to/some.wsdl) [function.file-get-contents]:无法打开流:HTTP 请求失败!

在最后的努力中,我尝试通过 curl_*功能,事实上我确实得到了我想要的东西。

... tl;博士?

  • SoapClient 和 file_get_contents 似乎超时(尽管不是明确的“无法打开流,连接超时”)
  • 似乎与流相关,因为curl 给了我我正在寻找的东西。
  • 我有很多代码依赖于 SoapClientfile_get_contents,因此切换到全卷曲解决方案实际上并不是一个选择。
  • 这不是 DNS 问题,因为我可以很好地解析外部名称(并且我的目标资源是 IP)
  • allow_url_fopen 已启用。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2024-12-26 02:50:11

allow_url_fopen 需要在 PHP 设置中On 才能使 file_get_contents 处理 URL。否则它会给你确切的错误。通过使用 phpinfo(); 调用加载页面来仔细检查您的 PHP 设置,以确保它们没有被不同的 php.ini 或 .htaccess 文件覆盖。

否则我猜是防火墙问题,但你说curl在PHP内部工作,它会以相同的方式打开套接字。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文