I want to keep the connection alive and responding line by line to the client much like a live log, like this:
for ($id = 0; $id < 100; $id++) {
$response = Http::get("http://api.example.com/user/{$id}");
response()->send('['.Carbon::now()->format('d/m/Y H:i:s')."] - {$response->status()} - {$response->body()}");
}
return response()->send('All requests done');
In that case, Laravel would send a request to an api and it would result in a line being sent back to the client listening, until the request is truly done by returning a response();
This would behave like an artisan command, outputting to the console a line with the current progress with $this->line('bla')
, but for http requests.
Although I can just concatenate to a single string and return the string in the end, it would be better to inform the user as the process is running.