-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathchannel.php
44 lines (42 loc) · 944 Bytes
/
channel.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
<?php
$chan = new Swoole\Channel(1024 * 256);
$n = 100000;
$bytes = 0;
if (pcntl_fork() > 0)
{
echo "Father\n";
for ($i = 0; $i < $n; $i++)
{
$data = str_repeat('A', rand(100, 200));
if ($chan->push($data) === false)
{
echo "channel full\n";
usleep(1000);
$i--;
continue;
}
$bytes += strlen($data);
// echo "#$i\tpush ".strlen($data)." bytes\n";
}
echo "total push bytes: $bytes\n";
var_dump($chan->stats());
}
else
{
echo "Child\n";
for ($i = 0; $i < $n; $i++)
{
$data = $chan->pop();
if ($data === false)
{
echo "channel empty\n";
usleep(1000);
$i--;
continue;
}
$bytes += strlen($data);
// echo "#$i\tpop " . strlen($data) . " bytes\n";
}
echo "total pop bytes: $bytes\n";
var_dump($chan->stats());
}