happydemon/transmission
Composer 安装命令:
composer require happydemon/transmission
包简介
A little helper for making calls to the Transmission Daemon RPC interface Edit
关键字:
README 文档
README
You can use this package to communicate with your transmission installation's web/RPC server.
You can set up transmission by going into preferences > remote > enable remote access.
This package was written against Transmission's RPC spec, if you ever need more info on what each call does or what data it returns, that's the best place to start.
Installation
First you'll need to pull in the library
composer require happydemon/transmission
Short intro
Next you'll need to set up the Transmission object.
$transmission = new \HappyDemon\Transmission\Transmission();
By not defining any config, the object will use sensible defaults to connect to transmission.
Let's retrieve the list of torrents we have in Transmission
var_dump($transmission->torrents()->get());
Config
When initialising a Transmission object you can pass an array with several config options;
ssl boolean
Is the transmission web server served over https?
host string
The host/IP the transmission web server is running on (defaults to 127.0.0.1).
port string
What port is the transmission web server running on (defaults to 9091).
url string
What endpoint is the transmission web server running on (defaults to /transmission/rpc).
username string
What username is used to authenticate? (empty by default)
password string
What password is used to authenticate? (empty by default)
Main torrent methods
Retrieving torrents
Retrieves the list of torrents you see in transmission.
$transmission->torrents()->get();
This will always return an array with HappyDemon\Services\Transmission\Torrents\Entity objects.
You can check out the class to see what properties are available to it.
You could also use it to retrieve a single or multiple torrents that you have the ID of:
// Get the torrent with id 1 $transmission->torrents()->get(1); // Get a few torrents $transmission->torrents()->get([1,6,12]);
Adding torrents
$torrent = $transmission->torrents()->addFromUrl($urlToTorrent); $torrent = $transmission->torrents()->addFile($filePath); $torrent = $transmission->torrents()->addFromBase64($fileBlob);
Using any of these methods will let you add new torrents.
Each time it will return a HappyDemon\Services\Transmission\Torrents\Entity object.
The catch is, only 3 properties will be set though: id, hashString & name.
You can also add some extra options that would overwrite Transmission's own default settings:
$torrent = $transmission->torrents()->addFromUrl($urlToTorrent, ['uploadLimit' => 512]);
Setting defaults
You could also overwrite Transmission's defaults 'globally'
$torrents = $transmission->torrents()->defaults(['uploadLimit' => 512]); $torrent = $torrents->addFromUrl($urlToTorrent);
Torrent entity methods
These are the methods that are available on a HappyDemon\Services\Transmission\Torrents\Entity object.
Actions
start
$torrent->start();
Starts the specific torrent.
stop
$torrent->stop();
Stops the specific torrent.
verify
$torrent->verify();
Verifies the specific torrent.
reannounce
$torrent->announce();
Reannounces the specific torrent.
remove
$torrent->remove();
Removes the specific torrent.
move
$torrent->move();
Moves the specific torrent to a different location on your file system.
update
Allows you to update some torrent-specific settings.
$torrent->settings($properties);
You could also update a singular torrent-setting like this:
// remove the download limit $torrent->setDownloadLimited(false);
// set the bandwidth priority $torrent->setBandwidthPriority(1);
// set the download limit (in K/s) $torrent->setDownloadLimit(1024*3);
// Mark files as wanted // Use an empty array for all files, use an array of ids to be more selective [0,2] // In this case we only want to download the second file $torrent->setFilesWanted([1]);
// Mark files as unwanted // Use an empty array for all files, use an array of ids to be more selective [0,2] // In this case we don't want to download the first file $torrent->setFilesUnwanted([0]);
// true if session upload limits are honored $torrent->setHonorsSessionLimits(true);
// Set a new directory for the torrent's contents $torrent->setLocation('c:/downloads');
// Set the peer limit (max amount of peer) $torrent->setPeerLimit(40);
// Set the priority for files to high // Use en empty array to update priority for all files // or use the file ids [0,2] $torrent->setPriorityHigh([]);
// Set the priority for files to low // Use en empty array to update priority for all files // or use the file ids [0,2] $torrent->setPriorityLow(false);
// Set the priority for files to normall // Use en empty array to update priority for all files // or use the file ids [0,2] $torrent->setPriorityNormal(false);
// Set the seed ratio limit $torrent->setSeedRatioLimit(1.2);
// Set the seed ratio mode // 0 = global, 1 = see seedRatioLimit, 2 = unlimitted $torrent->setSeedRatioMode(1);
// Change the upload limit (in K/s) $torrent->setUploadLimit(512);
// Should the torrent's upload be limitted? $torrent->setUploadLimited(false);
Getters
The entity has a lot of properties, however I've added a few getters for ease-of-use:
status
$torrent->status();
Will return the torrents status as a string, whereas $torrent->status only returns a number.
activityDate
$torrent->activityDate();
Will return a DateTime object, representing the last time torrent activity happened
addedDate
$torrent->addedDate();
Will return a DateTime object, representing the date/time the torrent was added.
doneDate
$torrent->doneDate();
Will return a DateTime object, representing time the torrent was completed.
percentDone
$torrent->percentDone();
Will return the percentage that the torrent is completed whereas $torrent->percentDone would return this as a float.
happydemon/transmission 适用场景与选型建议
happydemon/transmission 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rpc」 「torrent」 「transmission」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 happydemon/transmission 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 happydemon/transmission 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 happydemon/transmission 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Microservice RPC through message queues.
A Transmission-RPC API SDK for PHP with Laravel Support
Extract media information from torrent-like filename
Composer version of torrent-rw https://github.com/adriengibrat/torrent-rw
PHP Encrypted transmission
Control Nginx as a reverse proxy through plinker RPC
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-26