简体   繁体   English

wget适用于命令行,但不适用于PHP

[英]wget works for commandline but not in PHP

I'm trying to access some remote web sites within my PHP script, but the script keeps timing out. 我试图在我的PHP脚本中访问一些远程网站,但是该脚本一直在超时。

It only fails when run on the test web server, but not on the production web server. 它仅在测试Web服务器上运行时失败,而在生产Web服务器上运行时失败。

The script works just fine when accessing most other URLs, eg stackoverflow.com, or www.google.com. 当访问大多数其他URL(例如stackoverflow.com或www.google.com)时,该脚本可以正常工作。

I've tried it with the PHP commands file_get_contents($url) , as well as exec("wget $url" ) and exec("curl $url") , all of which fail. 我已经用PHP命令file_get_contents($url)以及exec("wget $url" )和exec("curl $url")尝试过,所有这些都失败了。 Again, most sites work fine, just not the ones I actually want. 同样,大多数站点都可以正常运行,但不是我真正想要的站点。

I can access the remote sites on the command-line via wget and curl. 我可以通过wget和curl在命令行上访问远程站点。 Even the PHP script works from the command-line! 甚至PHP脚本也可以从命令行运行! So I know the script works. 所以我知道脚本可以工作。

The script works when run on our production web server. 该脚本在我们的生产Web服务器上运行时有效。 But it doesn't work when it runs on the test web server. 但是,当它在测试Web服务器上运行时,它不起作用。

It appears that there is something peculiar about a GET request from the test server to the remote sites only when comes from Apache, but not the command-line. 看起来只有当来自Apache而不是命令行时,从测试服务器到远程站点的GET请求才有一些特殊之处。

How do I diagnose this problem? 我如何诊断这个问题?

Here are a few things to consider: 这里有几件事情要考虑:

  • Different system users for command line and web server. 命令行和Web服务器的不同系统用户。
  • Proxy server configuration (sometimes done via environment variables). 代理服务器配置(有时通过环境变量完成)。
  • Different network (DNS, routing, firewall, etc) configurations for test and production servers. 测试和生产服务器的不同网络(DNS,路由,防火墙等)配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM