-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Out of memory with Guzzle #30
Comments
Actually, the same for HttpClient; <?php
use JsonMachine\JsonMachine;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
require_once __DIR__ . '/vendor/autoload.php';
function httpClientChunks(ResponseStreamInterface $responseStream)
{
foreach ($responseStream as $chunk) {
yield $chunk->getContent();
}
}
$client = HttpClient::create();
$response = $client->request('GET', 'http://127.0.0.1:8001/storage/citylots.json');
$jsonChunks = httpClientChunks($client->stream($response));
foreach (JsonMachine::fromIterable($jsonChunks) as $key => $value) {
//
} % php memory.php
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 132120592 bytes) in /tmp/test/vendor/halaxa/json-machine/src/Parser.php on line 108
* Closing connection 0 |
You want to iterate |
Oh, actually I didn't even look at the data, I just googled "large json" to find some test-data. |
A bit surprising this will allocate a lot of memory with large json files, in this example a 181MB one (Found here; https://github.com/zemirco/sf-city-lots-json/blob/master/citylots.json)
I'm 100% guessing its due to json-machine is not registering as the
sink
for Guzzlehttp://docs.guzzlephp.org/en/stable/request-options.html#sink
The text was updated successfully, but these errors were encountered: