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

julianov's avatar

Http Request with laravel - it works asynchronously?

Hello everyone. The reason for my email is to consult you regarding the handling of http requests in Laravel. How does laravel handle API response time?

As you can see, 2 requests are executed and then the Laravel server responds. My question is, does Laravel not execute the response ( " return response()-> " ) until it gets the information from the Http request?

This is the controller method:

public function check_user (Request $request){

    $validated = $this->validate($request, [
        'user' => 'required',
    ]);

    $response_actor = Http::withHeaders([   
        'Authorization' => 'Bearer token',
    ])->get('http://somedomain:8000);

    $response_user = Http::withHeaders([
        'Authorization' => 'Bearer token',
    ])->get(' http://somedomain2:8000 );

    return response()->json([
        'status' => true,
        'user' => $response_user,
        'actor'=>$response_actor ,
    ], 201);

}
0 likes
2 replies
hamzaaslam's avatar

@julianov Laravel does not execute the response() statement until it receives some results from previous requests. And it's response time depends on the server's response time it waits for a response till the defined response time by the server if it did not get its response within the time it throws an error and if it receives its response within the time then it executes next statement and after successful execution of all statements then it executes response().

1 like

Please or to participate in this conversation.