为什么file_get_contents可以在google.com上使用,但不能在我的网站上使用? [英] Why does file_get_contents work with google.com but not with my site?

查看:104
本文介绍了为什么file_get_contents可以在google.com上使用,但不能在我的网站上使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ page1 = file_get_contents('http://www.google.com'); 

$ page2 = file_get_contents('http:// localhost:8000 / prueba');

当我回应结果时,使用Google它有效,但不适用于我的网站。当我把地址放在浏览器上的时候。这发生在我在django制作的所有网站上。 :(

)警告:file_get_contents( http:// localhost:8000 / prueba )[function.file-get内容]:无法打开流:连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机未能响应而建立连接失败。在C:\xampp\htdocs\中squirrelmail \plugins\captcha\backends\b2evo\b2evo.php on line 138



致命错误:在C:\\中超过60秒的最大执行时间\\ xampp \htdocs\squirrelmail\plugins\captcha\backends\b2evo\b2evo.php on line 138

解决方案

对于使用PHP内置Web服务器(在我的情况下使用Laravel)的任何人有这个问题,它是由您的请求被file_get_contents()/ curl函数阻塞导致的。



文件的开发者服务器说


如果请求被阻止,PHP应用程序将停摆。

由于PHP内置服务器是单线程的,请求服务器
上的另一个url将暂停第一个请求,并且它会超时。



作为解决方案,您可以使用nginx( LEMP stack )或其他网络服务器。 b
编辑:截至目前,我真的建议您使用 Homestead 作为PHP项目的开发环境。它为您节省大量配置工作,为更多项目创建虚拟主机和数据库配置。


$page1 = file_get_contents('http://www.google.com');

$page2 = file_get_contents('http://localhost:8000/prueba');

When I echo the results, with Google it works but not with my site. And when I put the address on the explorer works. And this happen with all the site that i make in django. :(

Warning: file_get_contents(http://localhost:8000/prueba) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\squirrelmail\plugins\captcha\backends\b2evo\b2evo.php on line 138

Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\squirrelmail\plugins\captcha\backends\b2evo\b2evo.php on line 138

解决方案

For anyone having this problem using PHP Built-in web server (with Laravel in my case), it is caused by your request being blocked by file_get_contents() / curl functions.

Docs of dev server say that

PHP applications will stall if a request is blocked.

Since the PHP built-in server is single threaded, requesting another url on your server will halt first request and it gets timed out.

As a solution, you can use nginx (LEMP stack) or other web servers.

Edit: As of now, I really suggest you to use Homestead as development environment for PHP projects. It saves you lots of work with configuration, creation of virtual hosts and DB configuration for more projects.

这篇关于为什么file_get_contents可以在google.com上使用,但不能在我的网站上使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆