PHP code example of ohffs / transmission-client

1. Go to this page and download the library: Download ohffs/transmission-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ohffs / transmission-client example snippets


$client = new \Ohffs\Transmission\Client('127.0.0.1', 9091, 'username', 'password');

$allTorrents = $client->all(); // returns an array of TorrentEntry's

$singleTorrent = $client->find(1234); // returns a single TorrentEntry or null

$borkedTorrent = $client->find(-1); // returns null

$ohno = $client->findOrFail(-1); // throws a RuntimeException

$newTorrent = $client->add('/path/to/an/exciting.torrent'); // returns a TorrentEntry

$pausedTorrent = $client->addPaused('/path/to/an/exciting.torrent'); // returns a TorrentEntry and pauses it in transmission

$client->remove(1234); // removes a torrent from transmission - returns a boolean

$singleTorrent = $client->find(1234);
var_dump($singleTorrent->toArray());
/*
 'name' => 'Some Exciting File',
 'id' => 1234,
 'doneDate' => 0,
 'eta' => 1000,
 'haveValid' => 0,
 'rateDownload' => 0,
 'rateUpload' => 0,
 'status' => 2,
 'totalSize' => 364514248,
 'downloadDir' => '/tmp/torrents',
 'percentDone' => 0.3,
*/

// And you can also get those as attributes on the object, eg :

echo $torrent->name;
// 'Some Exciting File'