Skip to content

Instantly share code, notes, and snippets.

@mortenscheel
Created November 7, 2023 14:50
Show Gist options
  • Save mortenscheel/5d9336274158b880a03ba67dae85d1c6 to your computer and use it in GitHub Desktop.
Save mortenscheel/5d9336274158b880a03ba67dae85d1c6 to your computer and use it in GitHub Desktop.
Example of how to process a streamed response from Laravel's Http client line by line.
<?php
use GuzzleHttp\Psr7\Utils;
use Illuminate\Support\Facades\Http;
$stream = Http::withOptions(['stream' => true])
->get('https://example.com')
->toPsrResponse()
->getBody();
while ($line = Utils::readLine($stream)) {
// Process line
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment