I'm having some weird problems with file_get_contents after moving my site to a new domain. I had to set up a new domain and IP address (using Plesk) to get a new ssl certificate working. Now my file_get_contents calling a script on the same domain is giving me this:
在将我的网站迁移到新域后,我遇到了一些奇怪的问题,即file_get_contents。我必须设置一个新域和IP地址(使用Plesk)才能获得新的ssl证书。现在我的file_get_contents在同一个域上调用脚本给了我这个:
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
无法打开流:HTTP请求失败!找不到HTTP / 1.1 404
If I call the same url using file_get_contents on another server it works fine, and if I call www.google.com from the server thats failing that works, so it only seems to be if I call a url on the same sever!
如果我在另一台服务器上使用file_get_contents调用相同的url它工作正常,如果我从服务器调用www.google.com失败,那么它似乎只是在同一个服务器上调用url!
I have a feeling it might have something to do with having two IPs with two different ssl certificates on the one server, when i file_get_contents / (index page) of the server from the server I get the plesk 'this is a new domain' page so its like apache isnt looking up the right virtual host when its called from its own sever.
我觉得它可能与在一台服务器上有两个不同的ssl证书的两个IP有关,当我从服务器获取服务器的file_get_contents /(索引页面)时我得到了plesk'这是一个新的域'页面所以当它从自己的服务器调用它时,它就像查找正确的虚拟主机一样。
To clarify (hopefully!):
澄清(希望!):
On the server hosting the domain:
在托管域的服务器上:
file_get_contents('https://mydomain.com?limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12');
gives "failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found"
给出“无法打开流:HTTP请求失败!找不到HTTP / 1.1 404”
file_get_contents('http://www.google.com');
works correctly
On another server:
在另一台服务器上
file_get_contents('https://mydomain.com?limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12');
works fine.
I have tried turning ssl off and I still get the same problem.
我试过关闭ssl,我仍然遇到同样的问题。
3 个解决方案
#1
5
I've had this problem too, when I working on a little test server at home. The domain name is resolved to your external IP address, and a request is sent. But because the request is coming from inside your network, the router doesn't recognise it as a normal request. It probably has a web interface for configuring it, and tries to return a page from its own management system, which is then not found at the path you specified.
当我在家里使用一台小型测试服务器时,我也遇到了这个问题。域名将解析为您的外部IP地址,并发送请求。但由于请求来自您的网络,路由器不会将其识别为正常请求。它可能有一个用于配置它的Web界面,并尝试从其自己的管理系统返回一个页面,然后在您指定的路径中找不到该页面。
In that case, I was working on a Windows PC, and I could solve it by adding the domain I was testing to my hosts
file, specifying 127.0.0.1 as the IP-address (or the IP-address of the server, if it is another machine within the same network). In Linux there should be a similar solution, I think.
在那种情况下,我在Windows PC上工作,我可以通过将我正在测试的域添加到我的hosts文件来解决它,指定127.0.0.1作为IP地址(或服务器的IP地址,如果它是同一网络中的另一台机器)。在Linux中,我认为应该有类似的解决方案。
The problem isn't PHP or your server, but your router.
问题不是PHP或您的服务器,而是您的路由器。
#2
#3
0
Try to do this :
尝试这样做:
file_get_contents('https://mydomain.com?'.urlencode('limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12'));
#1
5
I've had this problem too, when I working on a little test server at home. The domain name is resolved to your external IP address, and a request is sent. But because the request is coming from inside your network, the router doesn't recognise it as a normal request. It probably has a web interface for configuring it, and tries to return a page from its own management system, which is then not found at the path you specified.
当我在家里使用一台小型测试服务器时,我也遇到了这个问题。域名将解析为您的外部IP地址,并发送请求。但由于请求来自您的网络,路由器不会将其识别为正常请求。它可能有一个用于配置它的Web界面,并尝试从其自己的管理系统返回一个页面,然后在您指定的路径中找不到该页面。
In that case, I was working on a Windows PC, and I could solve it by adding the domain I was testing to my hosts
file, specifying 127.0.0.1 as the IP-address (or the IP-address of the server, if it is another machine within the same network). In Linux there should be a similar solution, I think.
在那种情况下,我在Windows PC上工作,我可以通过将我正在测试的域添加到我的hosts文件来解决它,指定127.0.0.1作为IP地址(或服务器的IP地址,如果它是同一网络中的另一台机器)。在Linux中,我认为应该有类似的解决方案。
The problem isn't PHP or your server, but your router.
问题不是PHP或您的服务器,而是您的路由器。
#2
4
Most hosting provides now block the furl_open
parameter which allows you to use file_get_contents()
to load data from an external url.
大多数托管提供现在阻止furl_open参数,允许您使用file_get_contents()从外部URL加载数据。
You can use CURL or a PHP
client library like Guzzle
您可以使用CURL或像Guzzle这样的PHP客户端库
#3
0
Try to do this :
尝试这样做:
file_get_contents('https://mydomain.com?'.urlencode('limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12'));