Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

36
vendor/swoole/examples/eof/async_client.php vendored Executable file
View File

@ -0,0 +1,36 @@
<?php
function send(swoole_client $cli)
{
$_send = str_repeat('A', rand(10000, 50000)) . "\r\n\r\n";
$cli->send($_send);
echo "send ".strlen($_send)." bytes\n";
}
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC); //异步非阻塞
$client->set(array('open_eof_check' => true, 'package_eof' => "\r\n\r\n"));
$client->on("connect", function(swoole_client $cli) {
send($cli);
});
$client->on("receive", function (swoole_client $cli, $data) {
static $i = 0;
if ($i % 100 == 1)
{
echo "received " . strlen($data) . " bytes\n";
}
$i ++;
//usleep(200000);
//send($cli);
});
$client->on("error", function(swoole_client $cli){
echo "error\n";
});
$client->on("close", function(swoole_client $cli){
echo "Connection close\n";
});
$client->connect('127.0.0.1', 9501);

75
vendor/swoole/examples/eof/client.php vendored Executable file
View File

@ -0,0 +1,75 @@
<?php
/**
* 分段发送数据
*
* @param swoole_client $client
* @param string $data
* @param int $chunk_size
*/
function send_chunk(swoole_client $client, $data, $chunk_size = 1024)
{
$len = strlen($data);
$chunk_num = intval($len / $chunk_size) + 1;
for ($i = 0; $i < $chunk_num; $i++)
{
if ($len < ($i + 1) * $chunk_size)
{
$sendn = $len - ($i * $chunk_size);
}
else
{
$sendn = $chunk_size;
}
$client->send(substr($data, $i * $chunk_size, $sendn));
}
}
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC); //同步阻塞
if(!$client->connect('127.0.0.1', 9501, 0.5, 0))
{
echo "Over flow. errno=".$client->errCode;
die("\n");
}
//for ($i = 0; $i < 10; $i++)
//{
// $client->send("hello world\r\n\r\n");
// echo "send\n";
//}
//exit;
$data = array(
'name' => __FILE__,
'content' => str_repeat('A', 8192 * rand(1, 3)), //800K
);
$_serialize_data = serialize($data);
$_send = $_serialize_data."__doit__";
echo "serialize_data length=".strlen($_serialize_data)."send length=".strlen($_send)."\n";
//send_chunk($client, $_send);
//
if(!$client->send($_send))
{
die("send failed.\n");
}
//$client->send("\r\n".substr($_serialize_data, 0, 8000));
echo $client->recv();
exit;
$client->send(substr($_serialize_data, 8000));
//usleep(500000);
if (!$client->send("\r\n\r\n"))
{
die("send failed.\n");
}
echo $client->recv();
//sleep(1);

31
vendor/swoole/examples/eof/server.php vendored Executable file
View File

@ -0,0 +1,31 @@
<?php
$serv = new swoole_server("127.0.0.1", 9501, SWOOLE_BASE);
$serv->set(array(
'package_eof' => "\r\n\r\n",
'open_eof_check' => true,
'open_eof_split' => true,
// 'worker_num' => 4,
'dispatch_mode' => 3,
'package_max_length' => 1024 * 1024 * 2, //2M
));
//$serv->on('connect', function ($serv, $fd) {
// //echo "[#" . posix_getpid() . "]\tClient:Connect.\n";
//});
$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data)
{
echo '#' . $serv->worker_id . " recv: " . strlen($data) . "\n";
for ($i = 0; $i < 1000; $i++)
{
$resp = str_repeat('A', rand(10000, 50000)) . "\r\n\r\n";
$serv->send($fd, $resp);
if ($i % 100 == 1)
{
sleep(1);
echo "send ".strlen($resp)." bytes\n";
}
}
});
//$serv->on('close', function ($serv, $fd) {
//echo "[#" . posix_getpid() . "]\tClient: Close.\n";
//});
$serv->start();