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

后端 未结 2 678
渐次进展
渐次进展 2020-12-01 19:34
$page1 = file_get_contents(\'http://www.google.com\');

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

When I echo the results, with

2条回答
  •  长情又很酷
    2020-12-01 20:15

    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 Laradock as development environment for PHP projects. It saves you lots of time with setup and configuration of different services (webserver, databases, queues, etc.).

提交回复
热议问题