-
Notifications
You must be signed in to change notification settings - Fork 45
/
example_seeder.php
61 lines (54 loc) · 2.61 KB
/
example_seeder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
// --------------------------------------
// This is how to start a seeding server.
// --------------------------------------
// [!] Run this file in CLI only!
// /usr/bin/php example_seeder.php
// Registering autoloader, essential to use the library.
require( dirname(__FILE__).'/lib/PHPTracker/Autoloader.php' );
PHPTracker_Autoloader::register();
// Persistense object implementing PHPTracker_Persistence_Interface.
// We use MySQL here. The object is initialized with its own config.
$persistence = new PHPTracker_Persistence_Mysql(
new PHPTracker_Config_Simple( array(
'db_host' => 'localhost',
'db_user' => 'misc',
'db_password' => 'misc',
'db_name' => 'misc',
) )
);
// Setting up seeder peer. This will listen to connections and serve files.
$peer = new PHPTracker_Seeder_Peer(
new PHPTracker_Config_Simple( array(
'persistence' => $persistence,
// PUBLIC address of the seeder server. This will be used for announcements (ie. sent to the clients).
'seeder_address' => '192.168.2.123',
// Don't forget the firewall!
'seeder_port' => 6881,
// Optional parameter for IP to open socket on if differs from external.
//'seeder_internal_address' => '192.168.2.123',
// Number telling how many processes should be forked to listen to incoming connections.
'peer_forks' => 10,
// If specified, gives a number of outsider seeders to make self-seeding stop.
// This saves you bandwidth - once your file is seeded by others, you can stop serving it.
// Number of seeders is permanently checked, but probably 1 is too few if you want your file to be available always.
'seeders_stop_seeding' => 5,
// Intializing file logger with default file path (/var/log/phptracker.log).
'logger' => new PHPTracker_Logger_File(),
)
) );
// We set up a seeding server which starts the seeding peer, and makes regular
// announcements to the database adding itself to the peer list for all
// active torrents.
$server = new PHPTracker_Seeder_Server(
new PHPTracker_Config_Simple( array(
'persistence' => $persistence,
'peer' => $peer,
// Intializing file logger with default file path (/var/log/phptracker.log).
'logger' => new PHPTracker_Logger_File(),
)
) );
// Starting "detached" means that process will unrelate from terminal and run as deamon.
// To run in terminal, you can use start().
// Detached running requires php-posix.
$server->startDetached();