Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danimohamadnejad's avatar

How can I call my routes using Http facade on same localhost server?

Following is my code to call index2 route:

     $res = Http::timeout(3)->get('http://localhost:8000/index2');
     dd($res);    

and I get following error:

cURL error 28: Operation timed out after 3002 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8000/index2

replacing localhost with 127.0.0.1 will just cause infinite loop? Have you ever faced such error? How are we going to call our localhost APIs using Http facade?

0 likes
5 replies
s4muel's avatar

this unfortunately is not possible (i mean, at least in this simple out-of-the-box form), because the php built-in server is single-threaded. but there is a chance, you have two options:

either start two servers and connect from one to another (different port),

or try this suggestion from internet, start the server with multiple workers:

PHP_CLI_SERVER_WORKERS=10 php artisan serve

have a look here: https://laracasts.com/discuss/channels/laravel/not-able-to-get-response-from-get-api-in-laravel

3 likes
Snapey's avatar
Snapey
Best Answer
Level 122

or install a webserver, eg xampp

1 like
danimohamadnejad's avatar

@Snapey Yes I tried xampp and it worked on localhost. I am trying to simulate microservices in form of packages on the same server. Up to this point it has been successful. Thank you

martinbean's avatar

@danimohamadnejad As @s4muel has mentioned, this isn’t possible when using artisan serve because it uses the built-in PHP server, which is single-threaded. This means that when you open your page, it uses the thread, and when you make a HTTP call, it’s trying to make a second request at the same time to your application, but the thread is already occupied trying to serve the initial request.

Why are you trying to make HTTP requests back to the same application in the first time?

1 like

Please or to participate in this conversation.