kleiram/transmission-php
PHP client library for Transmission’s RPC API. Control torrents from Laravel or any PHP app: add/start/stop, list and filter, set priorities, manage files and trackers, and read session stats. Simple, well-typed requests with authentication support.
Installation:
composer require kleiram/transmission-php
composer.json under autoload.psr-4.First Use Case: Connect to a Transmission daemon (e.g., local instance):
use Transmission\Client;
$client = new Client('http://localhost:9091/transmission/rpc');
$client->setAuth('username', 'password'); // or use token auth
Key Entry Points:
$client->session() to fetch daemon status.$client->torrentAdd() or $client->torrentGet().$client->configGet()/configSet() for daemon settings.Where to Look First:
examples/ directory (if available) for quick snippets.src/Transmission/Client.php for API reference.Torrent Management:
// Add a torrent from a magnet link
$client->torrentAdd([
'filename' => 'magnet:?xt=urn:btih...',
'download-dir' => '/path/to/downloads'
]);
// Get active torrents
$torrents = $client->torrentGet(['fields' => ['id', 'name', 'progress']]);
Session Monitoring:
$session = $client->session();
if ($session['isOpen']) {
$speed = $session['downloadSpeed'] + $session['uploadSpeed'];
// Log or display speed
}
Configuration Updates:
$config = $client->configGet();
$config['download-dir'] = '/new/path';
$client->configSet($config);
Error Handling:
try {
$client->torrentStart(123); // Start torrent with ID 123
} catch (Transmission\Exception\TransmissionException $e) {
Log::error("Transmission error: " . $e->getMessage());
}
schedule:run) to trigger Laravel events (e.g., TorrentCompleted).torrentGet() calls with Laravel’s cache system:
$torrents = Cache::remember('active_torrents', 30, function () use ($client) {
return $client->torrentGet(['fields' => ['id', 'name']]);
});
class TransmissionService {
protected $client;
public function __construct(Client $client) {
$this->client = $client;
}
public function getActiveTorrents() {
return $this->client->torrentGet(['fields' => ['id', 'name', 'status']]);
}
}
Deprecated Package:
transmission-rpc-spec.txt).Authentication:
setAuthToken() if available or upgrade the package.Rate Limiting:
use Symfony\Component\HttpClient\RetryStrategy;
$client = new Client('http://...');
$client->setHttpClient(HttpClient::create([
'timeout' => 30,
'retry' => RetryStrategy::fromOptions([
'max_retries' => 3,
'delay' => 1000,
]),
]));
Field Selection:
torrentGet() returns all fields by default, which is inefficient. Always specify fields:
// Bad: Returns 100+ fields
$client->torrentGet();
// Good: Only fetch needed fields
$client->torrentGet(['fields' => ['id', 'name', 'progress']]);
$client->setDebug(true); // Check if supported; otherwise, use a proxy like Guzzle middleware.
{'result': 'success', 'arguments': {...}} or {'result': 'failure', 'message': '...'}.$response = $client->rawRequest('torrent-get', ['fields' => ['id']]);
Transmission\Client to add missing RPC methods:
class ExtendedClient extends Client {
public function customMethod($params) {
return $this->rawRequest('custom-method', $params);
}
}
torrentGet() in a loop to emit Laravel events:
$torrents = $client->torrentGet();
foreach ($torrents as $torrent) {
if ($torrent['status'] === 'seeding') {
event(new TorrentSeeding($torrent));
}
}
Route::post('/transmission-webhook', function (Request $request) {
event(new TransmissionWebhookReceived($request->all()));
});
How can I help you explore Laravel packages today?