Pure PHP torrent client? [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
开发者_如何学Python Improve this questionI'm a developer for a PHP CMS and I want to add a BitTorrent capability to it. The CMS already lets users upload files which other users can then download, comment, etc. but I think this could be improved (especially for low-bandwidth sites) if the CMS could offer these downloads via BitTorrent, either via .torrent metadata files or via magnet links, so that the upload burden is shared.
It seems pretty straightforward, since there are loads of existing trackers out there I could plug in to, and the process of creating the required metadata is well documented, but the final piece of the puzzle is getting the site to act as a seed for the files, in case nobody else is seeding (eg. when it's newly added). I've spent a while searching, but can't find any PHP code which will seed files via BitTorrent, either via a tracker or via the DHT. There are plenty of frontends for torrent applications like rtorrent, Vuze, etc. but I'm looking for pure PHP, as I don't want to introduce dependencies which can't be satisfied by users on crappy, locked-down shared hosting accounts. Does anyone know of any PHP code capable of this floating around, or will I have to roll my own?
well what you want is theoretically possible.
there are some burdens like named virtual hosts and wrong listeing ports and execution time limits but you could theoretically follow the specs and do everything in php. you can open sockets and write raw data to it so theoretically anything is possible.
but its totally absurd and senseless.
however your problem is not new and there are solutions for that.
they are called propagating cdns.
most of them provide edgecasting for delivering content with high speed and low latency (this is the usual use case), but you can also use them to balance traffic.
most cdns of coruse cost money.
but there is a project devoted to this very specific problem. to cache content and deliver it for low bandwidth sites and only fetch it from there.
its called the coral cdn, you should check it out. the probably most used commercial ones are akamai, cachefly, and level3.
In the long run you HAVE to have your own server for this, because you need to run a torrent client on your server with your file(s) and (a) seed(s)? Then you could access via php, it would be fast and easy. I have done this with Transmission for a Linux server.
I can't see this to be a job for PHP. If I understand what you want to do correctly, it will not work at all on shared hosting due to the time limit a PHP script can run in.
Any torrent upload or download process that takes longer than the allowed 30 or 60 seconds would have to jump to the next page, reconnect, and restart the action. I can't see how this could work.
I think the best you can do in PHP is serve a file to a torrent site that takes care of the seeding. Clearbits (used by SO to provide the montly data dump) might be a useful service for that (but it's not free.)
You can get past the time limit that PHP has set by default in the php.ini file. However if your hosts sees this they might lock your account. Most shared hosting providers will lock your account if you use more than say 3% of the machines resources. Trying to write a bittorent client in PHP is absurd unless you have a dedicated machine to run it upon.
add this to your configuration file or any file that is included on every request.
// A Timeout of 5 minutes
ini_set('max_execution_time', 300);
Note that you have to specify the time in seconds unless you do something like the following
$timeout_minutes = 5;
ini_set('max_execution_time', 60 * $timeout_minutes);
May be I'm years late but you can use Amazon S3 for this. (Not just typical webseed.)
see document here: http://docs.aws.amazon.com/AmazonS3/latest/dev/S3Torrent.html
You just upload files from shared server to S3 then distribute the torrent file and just paid for outgoing bandwidth from S3.
精彩评论