amarkhai/parallel-downloader-bundle
Installation
composer require amarkhai/parallel-downloader-bundle
Ensure config/bundles.php includes Amarkhai\ParallelDownloaderBundle\ParallelDownloaderBundle::class.
First Use Case
Inject DownloadManager into a service/controller and call download() with an associative array of filename => url:
use Amarkhai\ParallelDownloaderBundle\Service\DownloadManager;
public function downloadFiles(DownloadManager $downloadManager)
{
$downloadManager->download([
'report.pdf' => 'https://example.com/report.pdf',
'image.jpg' => 'https://example.com/image.jpg',
]);
}
Files will save to var/downloads/ by default.
Batch Processing Use for downloading multiple files (e.g., user uploads, API responses):
$urls = $this->fetchFileUrlsFromDatabase();
$this->downloadManager->download($urls);
Subfolders Organize downloads by category:
$this->downloadManager->download($urls, 'reports/2023');
Custom Guzzle Options Apply per-request settings (timeouts, headers, etc.):
$options = ['timeout' => 30, 'headers' => ['User-Agent' => 'MyApp/1.0']];
$this->downloadManager->download($urls, null, $options);
download.start/download.end events (if supported).LoggerInterface (inject into DownloadManager if needed).$this->messageBus->dispatch(new DownloadFilesMessage($urls));
Concurrency Limits
Default download_concurrency: 10 may overwhelm servers. Adjust in config or dynamically:
# config/packages/amarkhai_parallel_downloader.yaml
parameters:
amarkhai_parallel_downloader.download_concurrency: 5
File Overwrites Duplicate filenames in the input array will overwrite silently. Validate keys first:
if (count(array_unique(array_keys($urls))) !== count($urls)) {
throw new \InvalidArgumentException('Duplicate filenames detected.');
}
Retry Logic Retries (default: 3) may hide transient issues. Monitor logs for failed URLs.
download_files_folder is writable:
chmod -R 775 var/downloads
options for on_error callbacks or enable Guzzle’s debug handler.Custom Storage
Override DownloadManager to use S3, database storage, etc.:
class CustomDownloadManager extends DownloadManager {
protected function saveFile(string $content, string $path): void {
// Custom logic (e.g., upload to S3)
}
}
Pre/Post-Processing
Hook into download() via dependency injection:
$this->downloadManager->download($urls, null, $options, $this);
Implement PostDownloadInterface for callbacks.
Config Overrides Use environment variables for dynamic settings:
parameters:
amarkhai_parallel_downloader.download_concurrency: '%env(int:DOWNLOAD_CONCURRENCY)%'
How can I help you explore Laravel packages today?