在torrent索引站点上保存种子

I'm building a torrent site where users can upload torrents.

What would be a good way to save the .torrent files?

I can think of several options:

Saving the torrent file itself in a folder on the server (not the best option since OS's have limitations saving lots of files in 1 folder)

Saving the torrent file itself in different folders per month

Saving the contents of the torrent file in the database (any limitations / performance issues / any other caveats?)

Any other options?

I'm use this: Saving the torrent file itself in different folders per month

May be you try Amazon S3? It's cheap, easy and fast.

Uploading them automatically saves .torrent files. http://www.tizag.com/phpT/fileupload.php has a good example. Give it a try.

If you're concerned about having too much files within a directory, you need to distribute the files across multiple directories. Storing them by month, day or week is one way how to do so. It depends a bit how many files you really have I would say.

You can try to more or less equally distribute the files within subdirectories by hashing their filename and use the whole or part of the hash to generate one or multiple subdirectory names:

$hash = md5($fileName);
$srotePath = sprintf('%s/%s', substr($hash,0,2), $fileName);

This would pick the first two character from an md5 hash (00-ff, 256 subdirectories) to generate the subdirectory.

The benefit compared with a date is, that you always can find out in which directory a file is stored when you have it's name.

That does also mean, that you can not have duplicate files with the same name (which might have worked for the date based subfolder).

using database is not at all good. just save them as static files and maybe even gzip them . just make sure to rename them uniquely with some kind of hashing .

if you don't have any problem in using external provider you can use TorCache

I would say saving the .torrent file in a weekly/monthly folder is the best option.

That way you can use the OS' filesystem cache, even if you store the .torrents outside the document root for limiting user access (in the end you will have to open() the file anyway)

Leaving torrents in the database would eventually lead to slow performance as the DB increases in size.