php namespace Teleguru Client Server use Socket Socket Undocumented cl

 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
62
<?php
namespace Teleguru\Client\Server;
use Socket\Socket;
/**
* Undocumented class
*/
class Application
{
protected $config;
protected $client;
protected $serverSocket;
public function __construct(array $config)
{
$this->config = \array_merge([
"app_id" => \getenv("APP_ID"),
"app_hash" => \getenv("APP_HASH"),
"server_port" => \getenv("SERVER_PORT"),
"server_max_connections" => \getenv("SERVER_MAX_CONNECTIONS")
], $config);
$this->init();
}
protected function init()
{
$this->client = new Client([
"app_id" => $this->config['app_id'],
"app_hash" => $this->config['app_hash']
]);
$this->serverSocket = new ServerSocket();
$this->serverSocket->setReusedPort(true)
->setMaxConnection($this->config['server_max_connections'])
->bind($this->config['server_port']);
$this->serverSocket->setConnectListener(new class($this->client) extends ConnectListener {
public function __invoke(Socket $socket)
{
// ..
$socket->close();
}
});
}
public function run()
{
$this->client->boot();
$this->serverSocket->listen()->run();
}
public function shutdown()
{
$this->serverSocket->close();
$this->client->close();
}
public function __destruct()
{
$this->shutdown();
}
}