$page1 = file_get_contents('http://www.google.com');
$page2 = file_get_contents('http://localhost:8000/prueba');
当我回显结果时,在 Google 上它可以工作,但在我的网站上却不起作用.当我把地址放在资源管理器上时.这发生在我在 django 中制作的所有网站上.:(
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. :(
警告:file_get_contents(http://localhost:8000/prueba
) [function.file-get-contents]:无法打开流:连接尝试失败,因为连接方没有正确一段时间后响应,或建立连接失败,因为连接的主机没有响应.在 C:xampphtdocssquirrelmailpluginscaptchaackends2evo2evo.php 第 138 行
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:xampphtdocssquirrelmailpluginscaptchaackends2evo2evo.php on line 138
致命错误:第 138 行 C:xampphtdocssquirrelmailpluginscaptchaackends2evo2evo.php 中的最大执行时间超过 60 秒
Fatal error: Maximum execution time of 60 seconds exceeded in C:xampphtdocssquirrelmailpluginscaptchaackends2evo2evo.php on line 138
对于使用 PHP 内置 Web 服务器(在我的情况下使用 Laravel)遇到此问题的任何人,这是由于您的请求被 file_get_contents()/卷曲函数.
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.
文档 开发服务器说
如果请求被阻止,PHP 应用程序将停止.
PHP applications will stall if a request is blocked.
由于PHP内置服务器是单线程的,在你的服务器上请求另一个url将停止第一个请求并超时.
Since the PHP built-in server is single threaded, requesting another url on your server will halt first request and it gets timed out.
作为解决方案,您可以使用适当的网络服务器(nginx、apache 等).
As a solution, you can use proper web server (nginx, apache etc.).
到目前为止,我真的建议您使用 Laravel Sail 作为 PHP 项目的开发环境.它为您设置和配置不同服务(网络服务器、数据库、队列等)节省了大量时间.
As of now, I really suggest you to use Laravel Sail as a development environment for PHP projects. It saves you lots of time with setup and configuration of different services (webserver, databases, queues, etc.).
这篇关于为什么 file_get_contents 可用于 google.com 而不能用于我的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!