-
Notifications
You must be signed in to change notification settings - Fork 729
/
Copy pathswoole_http_server.php
39 lines (31 loc) · 947 Bytes
/
swoole_http_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
<?php
class Server
{
private $http;
public function __construct() {
$this->http = new swoole_http_server("127.0.0.1", 9501);
$this->http->set(
array(
'worker_num' => 16,
'daemonize' => false,
'max_request' => 10000,
'dispatch_mode' => 1
)
);
$this->http->on('Start', array($this, 'onStart'));
$this->http->on('request' , array( $this , 'onRequest'));
$this->http->on('message' , array( $this , 'onMessage'));
$this->http->start();
}
public function onStart( $serv ) {
echo "Start\n";
}
public function onRequest($request, $response) {
$response->end("<h1>Hello Swoole.</h1>");
}
public function onMessage($request, $response) {
echo $request->message;
$response->message(json_encode(array("data1", "data2")));
}
}
new Server();