When Laravel makes an HTTP request to itself via Http::get(), Nginx locks the request in the same process. Laravel waits for the first request to finish before handling the second one. Since Laravel itself is already handling the first request, it can't handle the second one until the first finishes. This causes a deadlock where Laravel is waiting for a response from itself, but it can't process that response because it's busy waiting.
Use Http::async() to Make Requests Asynchronously
Here is modified code using async:
Route::get('testimoni', function () { $responses = Http::pool(fn ($pool) => [ $pool->get('http://localhost/api-project/api/menu-sidebar'), $pool->get('http://localhost/api-project/api/menu-sidebar'), ]); $result1 = $responses[0]->json(); $result2 = $responses[1]->json(); dump($result1, $result2); });
or you can do like this:
$result1 = app(\App\Http\Controllers\MenuSidebarController::class)->index();
It still same, when using pool for handle deadlock request. If using multiple request from Laravel API, it will be shown like this. The surprising thing is it only stuck when request Laravel API, if using Nest.JS Api or Fake API, it works like usually. Really, i'm very confused to handle this.
I mean the bug is from cURL Request, i test in sample PHP Project. It's not work too.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community