forked from swoole/benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_mode.php
42 lines (35 loc) · 911 Bytes
/
stream_mode.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
<?php
class Server
{
public $server;
public function run()
{
$this->server = new Swoole\Http\Server("0.0.0.0", 9501);
$this->server->set([
'worker_num' => 1,
'dispatch_mode' => 7
]);
// $this->server->on('Connect', [$this, 'onConnect']);
$this->server->on('Request', [$this, 'onRequest']);
// $this->server->on('Close', [$this, 'onClose']);
$this->server->start();
}
function log($msg)
{
echo $msg."\n";
}
public function onConnect($serv, $fd, $reactorId)
{
// $this->log("onConnect: fd=$fd");
}
public function onClose($serv, $fd, $reactorId)
{
// $this->log("onClose: fd=$fd");
}
public function onRequest($request, $response)
{
$response->end("data:".str_repeat('A', rand(100, 200)));
}
}
$server = new Server();
$server->run();