TelegramApiServer/server.php

51 lines
1.5 KiB
PHP
Raw Normal View History

<?php
require_once __DIR__ . '/bootstrap.php';
if (PHP_SAPI !== 'cli') {
throw new \Exception('Start in CLI');
}
2019-03-09 00:28:30 +01:00
$shortopts = 'a::p::s::';
2019-03-19 00:36:20 +01:00
$longopts = [
'address::', // ip адресс сервера, необязательное значение
'port::', // порт сервера, необязательное значение
2019-03-09 00:28:30 +01:00
'session::', //префикс session файла
'help', //нужна ли справка?
];
$options = getopt($shortopts, $longopts);
$options = [
2019-03-19 00:36:20 +01:00
'address' => $options['address'] ?? $options['a'] ?? '',
'port' => $options['port'] ?? $options['p'] ?? '',
'session' => $options['session'] ?? $options['s'] ?? '',
'help' => isset($options['help']),
];
if ($options['help']) {
$help = 'Fast, simple, async php telegram parser: MadelineProto + Swoole Server
2019-03-09 00:28:30 +01:00
usage: php server.php [--help] [-a|--address=127.0.0.1] [-p|--port=9503] [-s|--session=]
Options:
--help Show this message
-a --address Server ip (optional) (example: 127.0.0.1)
-p --port Server port (optional) (example: 9503)
2019-03-09 00:28:30 +01:00
-s --session Prefix for session file (optional) (example: xtrime)
Also all options can be set in .env file (see .env.example)
Example:
php server.php
';
echo $help;
exit;
}
2019-03-09 00:28:30 +01:00
if ($options['session']) {
$sessionFile = "{$root}/{$options['session']}_session.madeline";
} else {
2019-03-19 00:36:20 +01:00
$sessionFile = "{$root}/session.madeline";
2019-03-09 00:28:30 +01:00
}
$client = new TelegramApiServer\Client($sessionFile);
new TelegramApiServer\Server($client, $options);