I don't understand why but Guzzle doesn't download my file with getAsync if I don't wait the promise. But the reason I'm using getAsync is to continue my script while downloading the image.
Here is how I'm using it
protected function downloadImage ($url, $subDir, $filename)
{
$dir = '../public/files/' . $this->getAccountId() . '/';
if (!is_dir($dir)) {
mkdir($dir);
}
if (!is_dir($dir . $subDir . '/')) {
mkdir($dir . $subDir . '/');
}
$file = $dir . $subDir . '/' . $filename . '.jpg';
$client = new Client();
$promise = $client->getAsync($url, [ 'sink' => $file ]);
//$res = $promise->wait();
return $file;
}
public function myFunction ()
{
foreach ($aUrl as $url) {
$this->downloadImage($url, 'subFolder', 'myfilename')
}
}
Of course the final filename is different for each files but that's not the problem here