Created
November 7, 2023 14:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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