Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Transmission Php Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require kleiram/transmission-php
    
    • Verify the package is autoloaded in composer.json under autoload.psr-4.
  2. 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
    
  3. Key Entry Points:

    • Session Management: $client->session() to fetch daemon status.
    • Torrent Operations: $client->torrentAdd() or $client->torrentGet().
    • Configuration: $client->configGet()/configSet() for daemon settings.
  4. Where to Look First:

    • Source Code (if repo is found).
    • examples/ directory (if available) for quick snippets.
    • Method signatures in src/Transmission/Client.php for API reference.

Implementation Patterns

Common Workflows

  1. 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']]);
    
  2. Session Monitoring:

    $session = $client->session();
    if ($session['isOpen']) {
        $speed = $session['downloadSpeed'] + $session['uploadSpeed'];
        // Log or display speed
    }
    
  3. Configuration Updates:

    $config = $client->configGet();
    $config['download-dir'] = '/new/path';
    $client->configSet($config);
    
  4. Error Handling:

    try {
        $client->torrentStart(123); // Start torrent with ID 123
    } catch (Transmission\Exception\TransmissionException $e) {
        Log::error("Transmission error: " . $e->getMessage());
    }
    

Integration Tips

  • Queue System: Use Laravel queues to defer long-running operations (e.g., torrent seeding).
  • Event Listeners: Poll the daemon periodically (e.g., via schedule:run) to trigger Laravel events (e.g., TorrentCompleted).
  • Caching: Cache frequent torrentGet() calls with Laravel’s cache system:
    $torrents = Cache::remember('active_torrents', 30, function () use ($client) {
        return $client->torrentGet(['fields' => ['id', 'name']]);
    });
    
  • API Wrapping: Create a service class to abstract Transmission logic:
    class TransmissionService {
        protected $client;
    
        public function __construct(Client $client) {
            $this->client = $client;
        }
    
        public function getActiveTorrents() {
            return $this->client->torrentGet(['fields' => ['id', 'name', 'status']]);
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated Package:

    • Last release in 2013 may lack support for modern Transmission RPC (v2+). Test thoroughly.
    • Mitigation: Fork the repo or patch locally if needed (e.g., update transmission-rpc-spec.txt).
  2. Authentication:

    • Defaults to username/password but Transmission v2+ prefers session tokens.
    • Fix: Use setAuthToken() if available or upgrade the package.
  3. Rate Limiting:

    • No built-in retry logic for failed requests. Implement exponential backoff:
      use Symfony\Component\HttpClient\RetryStrategy;
      
      $client = new Client('http://...');
      $client->setHttpClient(HttpClient::create([
          'timeout' => 30,
          'retry' => RetryStrategy::fromOptions([
              'max_retries' => 3,
              'delay' => 1000,
          ]),
      ]));
      
  4. 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']]);
      

Debugging

  • Enable Verbose Logging:
    $client->setDebug(true); // Check if supported; otherwise, use a proxy like Guzzle middleware.
    
  • Check RPC Responses:
    • Transmission RPC returns {'result': 'success', 'arguments': {...}} or {'result': 'failure', 'message': '...'}.
    • Inspect raw responses with:
      $response = $client->rawRequest('torrent-get', ['fields' => ['id']]);
      

Extension Points

  1. Custom Requests:
    • Extend Transmission\Client to add missing RPC methods:
      class ExtendedClient extends Client {
          public function customMethod($params) {
              return $this->rawRequest('custom-method', $params);
          }
      }
      
  2. Event Dispatching:
    • Wrap torrentGet() in a loop to emit Laravel events:
      $torrents = $client->torrentGet();
      foreach ($torrents as $torrent) {
          if ($torrent['status'] === 'seeding') {
              event(new TorrentSeeding($torrent));
          }
      }
      
  3. Webhook Integration:
    • Use Transmission’s built-in webhooks (if enabled) to push events to a Laravel endpoint:
      Route::post('/transmission-webhook', function (Request $request) {
          event(new TransmissionWebhookReceived($request->all()));
      });
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours