-
Notifications
You must be signed in to change notification settings - Fork 44
/
server.php
57 lines (44 loc) · 2.04 KB
/
server.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
<?php
use TelegramRSS\Server\Server;
use TelegramRSS\TgClient;
if (PHP_SAPI !== 'cli') {
throw new \RuntimeException('Start in CLI');
}
$longopts = [
'server-address::', // ip адрес сервера, необязательное значение
'server-port::', // порт сервера, необязательное значение
'client-address::', // ip телеграм-клиента, необязательное значение
'client-port::', // порт телеграм-клиента, необязательное значение
'docker::', //сгенерировать docker-совместимый .env
'help', //нужна ли справка?
];
$options = getopt('', $longopts);
$options = [
'server-address' => $options['server-address'] ?? '',
'server-port' => (int)($options['server-port'] ?? 0),
'client-address' => $options['client-address'] ?? '',
'client-port' => (int)($options['client-port'] ?? 0),
'docker' => isset($options['docker']),
'help' => isset($options['help']),
];
if ($options['help']) {
$help = 'Fast, simple, async php telegram rss/json server (based on Amphp Http Server)
usage: php server.php [--help] [--server-address=127.0.0.1] [--server-port=9504] [--client-address=127.0.0.1] [--client-port=9503]
Options:
--help Show this message
--server-address Server address (optional) (default: 127.0.0.1)
--server-port Server port (optional) (default: 9504)
--client-address Telegram Client address (optional) (default: 127.0.0.1)
--client-port Telegram Client port (optional) (default: 9503)
Also all options can be set in .env.docker file (see .env.docker.example)
If you dont have Telegram client install from here:
https://github.com/xtrime-ru/TelegramApiServer
Example:
php server.php
';
echo $help;
exit;
}
require_once __DIR__ . '/bootstrap.php';
$client = new TgClient($options['client-address'], $options['client-port']);
new Server($client, $options['server-address'], $options['server-port']);