Quickstart
The simplest way to use the package is to download a file from a queued job.
After installing the package, open the .env file and add the following keys:
ARIA2_RPC_URL=http://127.0.0.1:6800/jsonrpcARIA2_RPC_SECRET=change-me
Create a job:
php artisan make:job DownloadFile --no-interaction
Open the generated job and replace its handle method:
<?php namespace App\Jobs; use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Queue\Queueable;use Dasundev\LaravelAria2\Facades\Aria2;use Dasundev\LaravelAria2\Transfer\TransferStatus; class DownloadFile implements ShouldQueue{ use Queueable; public function __construct( public string $url, public string $directory, ) {} public function handle(): void { Aria2::url($this->url) ->dir($this->directory) ->onProgress(function (TransferStatus $status) { logger()->info('aria2 progress', $status->toArray()); }) ->download(); }}
Dispatch it:
use App\Jobs\DownloadFile; DownloadFile::dispatch( 'https://example.com/file.iso', storage_path('app/downloads/1'),);
The job blocks until aria2 finishes or fails. Progress callbacks and events fire as fields change.