-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathsend_1m.php
30 lines (30 loc) · 1.01 KB
/
send_1m.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
<?php
$serv = new Swoole\Server("0.0.0.0", 9509);
$serv->set(array('worker_num' => 1));
$serv->on('workerStart', function($serv, $worker_id) {
//if($worker_id == 0) $serv->addtimer(500);
});
$serv->on('connect', function ($serv, $fd, $reactor_id){
$serv->array['fd'] = &strval($fd);
echo "[#".posix_getpid()."]\tClient@[$fd:$reactor_id]: Connect.\n";
});
$serv->on('receive', function ($serv, $fd, $reactor_id, $data) {
//echo "[#".posix_getpid()."]\tClient[$fd]: $data\n";
$array = array('A', 'B', 'C', 'D', 'E', 'F', 'G');
$data = '';
$n_bytes = 0;
for ($i = 0; $i < 10; $i++)
{
$_str = str_repeat($array[$i % 7], 4030) . "\n";
//$serv->send($fd, $_str);
$n_bytes += strlen($_str);
$data .= $_str;
}
echo "send " . $n_bytes . " bytes\n";
$serv->send( $serv->array['fd'], $data);
$serv->close($fd);
});
$serv->on('close', function ($serv, $fd, $reactor_id) {
echo "[#".posix_getpid()."]\tClient@[$fd:$reactor_id]: Close.\n";
});
$serv->start();