Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

php - Why does file_get_contents work with google.com but not with my site?

$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:xampphtdocssquirrelmailpluginscaptchaackends2evo2evo.php on line 138

Fatal error: Maximum execution time of 60 seconds exceeded in C:xampphtdocssquirrelmailpluginscaptchaackends2evo2evo.php on line 138

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 proper web server (nginx, apache etc.).

Edit: 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.).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...