I have the Http request in my controller:
$url = url('/api/list-professional');
$professionals = Http::get($url);
These two lines work perfectly fine when I use them in my phpUnit Tests,
But when I use them inside a controller it just gets a time out.
Anyone knows why?
2
Answers
Wrap your
Http::get
call in a try-catch block to capture and log any possible exceptions.You can also increase the timeout.
The reason for this is that
php artisan serve
is a single-thread application. So when we use an HTTP client to request from it to itself, it basically just tries to finish the guzzle HTTP client (as a client) first then comes to finish that request (as a server), which is impossible.So create two ports using php artisan serve . One is for HTTP client and another port is to access from browser
for example if you have created port 8000 and 8001 then
and use 8000 port to access from browser