1
|
|
|
<?php |
2
|
|
|
namespace PHPDaemon\Servers\HTTP; |
3
|
|
|
|
4
|
|
|
use PHPDaemon\Config\Entry\Size; |
5
|
|
|
use PHPDaemon\Config\Entry\Time; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @package NetworkServer |
9
|
|
|
* @subpackage HTTPServer |
10
|
|
|
* @author Vasily Zorin <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Pool extends \PHPDaemon\Network\Server |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string Variables order "GPC" |
16
|
|
|
*/ |
17
|
|
|
public $variablesOrder; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var WebSocketServer WebSocketServer instance |
21
|
|
|
*/ |
22
|
|
|
public $WS; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Called when worker is going to update configuration. |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
public function onConfigUpdated() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
parent::onConfigUpdated(); |
31
|
|
|
|
32
|
|
|
if (($order = ini_get('request_order')) || ($order = ini_get('variables_order'))) { |
33
|
|
|
$this->variablesOrder = $order; |
34
|
|
|
} else { |
35
|
|
|
$this->variablesOrder = null; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Called when the worker is ready to go. |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function onReady() |
44
|
|
|
{ |
45
|
|
|
parent::onReady(); |
46
|
|
|
$this->WS = \PHPDaemon\Servers\WebSocket\Pool::getInstance($this->config->wssname->value, false); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Setting default config options |
51
|
|
|
* Overriden from AppInstance::getConfigDefaults |
52
|
|
|
* @return array|bool |
53
|
|
|
*/ |
54
|
|
View Code Duplication |
protected function getConfigDefaults() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
/* [string|array] Listen addresses */ |
58
|
|
|
'listen' => 'tcp://0.0.0.0', |
59
|
|
|
|
60
|
|
|
/* [integer] Listen port */ |
61
|
|
|
'port' => 80, |
62
|
|
|
|
63
|
|
|
/* [boolean] Enable X-Sendfile? */ |
64
|
|
|
'send-file' => 0, |
65
|
|
|
|
66
|
|
|
/* [string] Directory for X-Sendfile */ |
67
|
|
|
'send-file-dir' => '/dev/shm', |
68
|
|
|
|
69
|
|
|
/* [string] Prefix for files used for X-Sendfile */ |
70
|
|
|
'send-file-prefix' => 'http-', |
71
|
|
|
|
72
|
|
|
/* [boolean] Use X-Sendfile only if server['USE_SENDFILE'] provided. */ |
73
|
|
|
'send-file-onlybycommand' => 0, |
74
|
|
|
|
75
|
|
|
/* [boolean] Expose PHPDaemon version by X-Powered-By Header */ |
76
|
|
|
'expose' => 1, |
77
|
|
|
|
78
|
|
|
/* [Time] Keepalive time */ |
79
|
|
|
'keepalive' => new Time('0s'), |
80
|
|
|
|
81
|
|
|
/* [Size] Chunk size */ |
82
|
|
|
'chunksize' => new Size('8k'), |
83
|
|
|
|
84
|
|
|
/* [string] Default charset */ |
85
|
|
|
'defaultcharset' => 'utf-8', |
86
|
|
|
|
87
|
|
|
/* [string] Related WebSocketServer instance name */ |
88
|
|
|
'wss-name' => '', |
89
|
|
|
|
90
|
|
|
/* [string] Related FlashPolicyServer instance name */ |
91
|
|
|
'fps-name' => '', |
92
|
|
|
|
93
|
|
|
/* [Size] Maximum uploading file size. */ |
94
|
|
|
'upload-max-size' => new Size(ini_get('upload_max_filesize')), |
95
|
|
|
|
96
|
|
|
/* [string] Reponder application (if you do not want to use AppResolver) */ |
97
|
|
|
'responder' => null, |
98
|
|
|
]; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.