-
Notifications
You must be signed in to change notification settings - Fork 729
/
Copy pathswoole_mysql_pool_client.php
60 lines (48 loc) · 1.17 KB
/
swoole_mysql_pool_client.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
class Client
{
private $client;
private $i = 0;
private $time;
public function __construct() {
$this->client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
$this->client->on('Connect', array($this, 'onConnect'));
$this->client->on('Receive', array($this, 'onReceive'));
$this->client->on('Close', array($this, 'onClose'));
$this->client->on('Error', array($this, 'onError'));
}
public function connect() {
$fp = $this->client->connect("127.0.0.1", 9501 , 1);
if( !$fp ) {
echo "Error: {$fp->errMsg}[{$fp->errCode}]\n";
return;
}
}
public function onReceive( $cli, $data ) {
$this->i ++;
if( $this->i >= 10000 ) {
echo "Use Time: " . ( time() - $this->time);
exit(0);
}
else {
$cli->send("Get");
}
}
public function onConnect( $cli) {
$cli->send("Get");
$this->time = time();
}
public function onClose( $cli) {
echo "Client close connection\n";
}
public function onError() {
}
public function send($data) {
$this->client->send( $data );
}
public function isConnected() {
return $this->client->isConnected();
}
}
$cli = new Client();
$cli->connect();