Quickstart
To begin your Laravel Aria2 journey, we will download a file from a queued job. This example is a great way to experience the package for the first time, as it demonstrates the fluent API in the simplest way possible.
Prerequisites
Before we start, make sure you have:
- Laravel 13
pullr/laravel-aria2installedaria2crunning with JSON-RPC enabled
Configure the RPC endpoint
Copy the following keys into your application's .env file:
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 Pullr\LaravelAria2\Facades\Aria2;use Pullr\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.
We've only scratched the surface. Keep reading to explore metadata, cancellation, events, faking, and the low-level RPC client.