I'm trying to download files asynchronously using Guzzle 6, but the documentation seems vague and cannot find useful examples.
What I'm not sure about is how should I save the received data?
I am currently doing it like this:
$successHandler = function (Response $response, $index) use ($files) { $file = fopen($files[$index], 'a'); $handle = $response->getBody(); while (!$handle->eof()) { fwrite($file, $handle->read(2048)); } fclose($file); };
Is it really asynchronous?
Since if we enter one callback and start a loop, how can we get data from others at the same time?
Is there a more direct way to say when a request is made, where should the response be stored? (or directly passing the stream for this).
source share