You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
49
vendor/swoole/tests/swoole_client_async/big_package_memory_leak.phpt
vendored
Executable file
49
vendor/swoole/tests/swoole_client_async/big_package_memory_leak.phpt
vendored
Executable file
@ -0,0 +1,49 @@
|
||||
--TEST--
|
||||
swoole_client: big_package_memory_leak
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$tcp_server = __DIR__ . "/../include/memoryleak/tcp_client_memory_leak/tcp_serv.php";
|
||||
$closeServer = start_server($tcp_server, "127.0.0.1", 9001);
|
||||
|
||||
$mem = memory_get_usage(true);
|
||||
fclose(STDOUT);
|
||||
ini_set("memory_limit", "100m");
|
||||
$cli = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
$cli->on("connect", function (swoole_client $cli)
|
||||
{
|
||||
$cli->send(str_repeat("\0", 1024 * 1024 * 1.9));
|
||||
});
|
||||
$cli->on("receive", function (swoole_client $cli, $data)
|
||||
{
|
||||
$cli->send($data);
|
||||
});
|
||||
$cli->on("error", function (swoole_client $cli)
|
||||
{
|
||||
echo "error";
|
||||
});
|
||||
$cli->on("close", function (swoole_client $cli) use ($closeServer)
|
||||
{
|
||||
echo "closed\n";
|
||||
$closeServer();
|
||||
});
|
||||
$cli->connect("127.0.0.1", 9001);
|
||||
assert(memory_get_usage(true) == $mem);
|
||||
echo "SUCCESS";
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
SUCCESS
|
||||
closed
|
114
vendor/swoole/tests/swoole_client_async/buffer_full.php.phpt
vendored
Executable file
114
vendor/swoole/tests/swoole_client_async/buffer_full.php.phpt
vendored
Executable file
@ -0,0 +1,114 @@
|
||||
--TEST--
|
||||
swoole_client: onBufferFull & onBufferEmpty
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$port = get_one_free_port();
|
||||
|
||||
$pm = new ProcessManager;
|
||||
$pm->parentFunc = function ($pid) use ($port)
|
||||
{
|
||||
Swoole\Async::set(['log_level' => 5, 'display_errors' => false]);
|
||||
$client = new Swoole\Client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
$client->set(['socket_buffer_size' => 1 * 1024 * 1024,]);
|
||||
$client->buffer = array();
|
||||
|
||||
$client->on("connect", function (Swoole\Client $cli)
|
||||
{
|
||||
for ($i = 0; $i < 1024; $i++)
|
||||
{
|
||||
$data = str_repeat('A', 8192);
|
||||
if ($cli->send($data) === false and $cli->errCode == 1008) {
|
||||
$cli->buffer[] = $data;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$client->on("receive", function (Swoole\Client $cli, $data)
|
||||
{
|
||||
$cli->send(pack('N', 8) . 'shutdown');
|
||||
$cli->close();
|
||||
assert($data === md5_file(TEST_IMAGE));
|
||||
});
|
||||
|
||||
$client->on("error", function($cli){
|
||||
echo "Connect failed\n";
|
||||
});
|
||||
|
||||
$client->on("close", function($cli){
|
||||
|
||||
});
|
||||
|
||||
$client->on("bufferEmpty", function (Swoole\Client $cli)
|
||||
{
|
||||
echo "bufferEmpty\n";
|
||||
foreach ($cli->buffer as $k => $data)
|
||||
{
|
||||
if ($cli->send($data) === false and $cli->errCode == 1008)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($cli->buffer[$k]);
|
||||
}
|
||||
}
|
||||
if (count($cli->buffer) == 0)
|
||||
{
|
||||
$cli->close();
|
||||
}
|
||||
});
|
||||
|
||||
$client->on("bufferFull", function (Swoole\Client $cli)
|
||||
{
|
||||
echo "bufferFull\n";
|
||||
});
|
||||
|
||||
$client->connect(TCP_SERVER_HOST, $port, 0.5);
|
||||
Swoole\Event::wait();
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm, $port)
|
||||
{
|
||||
$socket = stream_socket_server("tcp://0.0.0.0:{$port}", $errno, $errstr) or die("$errstr ($errno)<br />\n");
|
||||
$pm->wakeup();
|
||||
while ($conn = stream_socket_accept($socket))
|
||||
{
|
||||
for ($i = 0; $i < 4; $i++)
|
||||
{
|
||||
usleep(500000);
|
||||
for ($j = 0; $j < 256; $j++)
|
||||
{
|
||||
$data = fread($conn, 8192);
|
||||
}
|
||||
}
|
||||
fclose($conn);
|
||||
break;
|
||||
}
|
||||
fclose($socket);
|
||||
};
|
||||
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
--EXPECT--
|
||||
bufferFull
|
||||
bufferEmpty
|
||||
bufferFull
|
||||
bufferEmpty
|
||||
bufferFull
|
||||
bufferEmpty
|
||||
bufferFull
|
||||
bufferEmpty
|
45
vendor/swoole/tests/swoole_client_async/connect_dns.phpt
vendored
Executable file
45
vendor/swoole/tests/swoole_client_async/connect_dns.phpt
vendored
Executable file
@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
swoole_client: connect & dns
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$cli = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
|
||||
$cli->on("connect", function (swoole_client $cli) {
|
||||
assert($cli->isConnected() === true);
|
||||
$cli->send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.50.1-DEV\r\nAccept: */*\r\n\r\n");
|
||||
});
|
||||
|
||||
$cli->on("receive", function (swoole_client $cli, $data) {
|
||||
assert(strlen($data) > 0);
|
||||
$cli->close();
|
||||
assert($cli->isConnected() === false);
|
||||
});
|
||||
|
||||
$cli->on("error", function (swoole_client $cli) {
|
||||
echo "ERROR";
|
||||
});
|
||||
|
||||
$cli->on("close", function (swoole_client $cli) {
|
||||
echo "SUCCESS";
|
||||
});
|
||||
|
||||
$cli->connect("www.baidu.com", 80, 2.0);
|
||||
|
||||
swoole_event::wait();
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
SUCCESS
|
32
vendor/swoole/tests/swoole_client_async/connect_refuse.phpt
vendored
Executable file
32
vendor/swoole/tests/swoole_client_async/connect_refuse.phpt
vendored
Executable file
@ -0,0 +1,32 @@
|
||||
--TEST--
|
||||
swoole_client: connect refuse
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$cli = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
$cli->on("connect", function(swoole_client $cli) {
|
||||
assert(false);
|
||||
});
|
||||
$cli->on("receive", function(swoole_client $cli, $data) {
|
||||
assert(false);
|
||||
});
|
||||
$cli->on("error", function(swoole_client $cli) { echo "error\n"; });
|
||||
$cli->on("close", function(swoole_client $cli) { echo "close\n"; });
|
||||
|
||||
$cli->connect("127.0.0.1", 65535);
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
error
|
38
vendor/swoole/tests/swoole_client_async/connect_timeout.phpt
vendored
Executable file
38
vendor/swoole/tests/swoole_client_async/connect_timeout.phpt
vendored
Executable file
@ -0,0 +1,38 @@
|
||||
--TEST--
|
||||
swoole_client: connect_host_not_found
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
$cli = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
$cli->on("connect", function(swoole_client $cli) {
|
||||
assert(false);
|
||||
});
|
||||
$cli->on("receive", function(swoole_client $cli, $data) {
|
||||
assert(false);
|
||||
});
|
||||
$cli->on("error", function(swoole_client $cli) {
|
||||
echo "error\n";
|
||||
});
|
||||
$cli->on("close", function(swoole_client $cli) {
|
||||
echo "close\n";
|
||||
});
|
||||
|
||||
$cli->connect("192.0.0.1", 9000, 0.1);
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
error
|
21
vendor/swoole/tests/swoole_client_async/connect_twice.phpt
vendored
Executable file
21
vendor/swoole/tests/swoole_client_async/connect_twice.phpt
vendored
Executable file
@ -0,0 +1,21 @@
|
||||
--TEST--
|
||||
swoole_client: connect twice
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
require_once __DIR__ . '/../include/api/swoole_client/connect_twice.php';
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
error
|
131
vendor/swoole/tests/swoole_client_async/eof.phpt
vendored
Executable file
131
vendor/swoole/tests/swoole_client_async/eof.phpt
vendored
Executable file
@ -0,0 +1,131 @@
|
||||
--TEST--
|
||||
swoole_client: eof protocol [async]
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$pm = new ProcessManager;
|
||||
$port = get_one_free_port();
|
||||
$pm->parentFunc = function ($pid) use ($port)
|
||||
{
|
||||
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
$client->set(['open_eof_check' => true, 'open_eof_split' => true, "package_eof" => "\r\n\r\n"]);
|
||||
|
||||
$client->on("connect", function (swoole_client $cli)
|
||||
{
|
||||
$cli->send("recv\r\n\r\n");
|
||||
});
|
||||
|
||||
$client->on("receive", function(swoole_client $cli, $pkg) use ($pid) {
|
||||
static $i = 0;
|
||||
$i++;
|
||||
|
||||
//小包
|
||||
if ($i <= 1000)
|
||||
{
|
||||
assert($pkg and strlen($pkg) <= 2048);
|
||||
if ($i == 1000)
|
||||
{
|
||||
echo "SUCCESS\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
//慢速发送
|
||||
elseif ($i <= 1100)
|
||||
{
|
||||
assert($pkg and strlen($pkg) <= 8192);
|
||||
if ($i == 1100)
|
||||
{
|
||||
echo "SUCCESS\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
//大包
|
||||
else
|
||||
{
|
||||
assert($pkg != false);
|
||||
$_pkg = unserialize($pkg);
|
||||
assert(is_array($_pkg));
|
||||
assert($_pkg['i'] == $i - 1100 - 1);
|
||||
assert($_pkg['data'] <= 256 * 1024);
|
||||
if ($i == 2100) {
|
||||
echo "SUCCESS\n";
|
||||
$cli->close();
|
||||
swoole_process::kill($pid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$client->on("error", function(swoole_client $cli) {
|
||||
print("error");
|
||||
});
|
||||
|
||||
$client->on("close", function(swoole_client $cli) {
|
||||
swoole_event_exit();
|
||||
});
|
||||
|
||||
if (!$client->connect('127.0.0.1', $port, 0.5, 0))
|
||||
{
|
||||
echo "Over flow. errno=" . $client->errCode;
|
||||
die("\n");
|
||||
}
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm, $port)
|
||||
{
|
||||
$serv = new swoole_server("127.0.0.1", $port, SWOOLE_BASE);
|
||||
$serv->set(array(
|
||||
'package_eof' => "\r\n\r\n",
|
||||
'open_eof_check' => true,
|
||||
'open_eof_split' => true,
|
||||
'dispatch_mode' => 3,
|
||||
'package_max_length' => 1024 * 1024 * 2, //2M
|
||||
'socket_buffer_size' => 128 * 1024 * 1024,
|
||||
"worker_num" => 1,
|
||||
'send_yield' => true,
|
||||
'log_file' => '/data/logs/swoole.log',
|
||||
));
|
||||
$serv->on("WorkerStart", function (\swoole_server $serv) use ($pm)
|
||||
{
|
||||
$pm->wakeup();
|
||||
});
|
||||
$serv->on('receive', function (swoole_server $serv, $fd, $rid, $data)
|
||||
{
|
||||
//小包
|
||||
for ($i = 0; $i < 1000; $i++)
|
||||
{
|
||||
$serv->send($fd, str_repeat('A', rand(100, 2000)) . "\r\n\r\n");
|
||||
}
|
||||
//慢速发送
|
||||
for ($i = 0; $i < 100; $i++)
|
||||
{
|
||||
$serv->send($fd, str_repeat('A', rand(1000, 2000)));
|
||||
usleep(rand(10000, 50000));
|
||||
$serv->send($fd, str_repeat('A', rand(2000, 4000)) . "\r\n\r\n");
|
||||
}
|
||||
//大包
|
||||
for ($i = 0; $i < 1000; $i++)
|
||||
{
|
||||
$serv->send($fd, serialize(['i' => $i, 'data' => str_repeat('A', rand(20000, 256 * 1024))]) . "\r\n\r\n");
|
||||
}
|
||||
});
|
||||
$serv->start();
|
||||
};
|
||||
$pm->async = true;
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
--EXPECT--
|
||||
SUCCESS
|
||||
SUCCESS
|
||||
SUCCESS
|
76
vendor/swoole/tests/swoole_client_async/eof_close.phpt
vendored
Executable file
76
vendor/swoole/tests/swoole_client_async/eof_close.phpt
vendored
Executable file
@ -0,0 +1,76 @@
|
||||
--TEST--
|
||||
swoole_client: eof protocol [async] [close]
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$pm = new ProcessManager;
|
||||
$pm->parentFunc = function ($pid) use ($pm)
|
||||
{
|
||||
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
$client->set(['open_eof_check' => true, 'open_eof_split' => true, "package_eof" => "\r\n\r\n"]);
|
||||
|
||||
$client->on("connect", function (swoole_client $cli)
|
||||
{
|
||||
$cli->send("recv\r\n\r\n");
|
||||
});
|
||||
|
||||
$client->on("receive", function (swoole_client $cli, $pkg) use ($pid, $pm) {
|
||||
echo "RECEIVED\n";
|
||||
$cli->close();
|
||||
$pm->kill();
|
||||
});
|
||||
|
||||
$client->on("error", function(swoole_client $cli) {
|
||||
print("error");
|
||||
});
|
||||
|
||||
$client->on("close", function(swoole_client $cli) {
|
||||
echo "CLOSED\n";
|
||||
});
|
||||
|
||||
if (!$client->connect('127.0.0.1', 9501, 0.5, 0))
|
||||
{
|
||||
echo "Over flow. errno=" . $client->errCode;
|
||||
die("\n");
|
||||
}
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm)
|
||||
{
|
||||
$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,
|
||||
'dispatch_mode' => 3,
|
||||
'package_max_length' => 1024 * 1024 * 2, //2M
|
||||
'socket_buffer_size' => 128 * 1024 * 1024,
|
||||
"worker_num" => 1,
|
||||
'log_file' => '/dev/null',
|
||||
));
|
||||
$serv->on("WorkerStart", function (\swoole_server $serv) use ($pm) {
|
||||
$pm->wakeup();
|
||||
});
|
||||
$serv->on('receive', function (swoole_server $serv, $fd, $rid, $data) {
|
||||
$serv->send($fd, str_repeat('A', rand(100, 2000)) . "\r\n\r\n");
|
||||
});
|
||||
$serv->start();
|
||||
};
|
||||
$pm->async = true;
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
--EXPECT--
|
||||
RECEIVED
|
||||
CLOSED
|
52
vendor/swoole/tests/swoole_client_async/getSocket_bug.phpt
vendored
Executable file
52
vendor/swoole/tests/swoole_client_async/getSocket_bug.phpt
vendored
Executable file
@ -0,0 +1,52 @@
|
||||
--TEST--
|
||||
swoole_client: getSocket debug
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc';
|
||||
if (method_exists('swoole_client', 'getSocket') === false) {
|
||||
exit("require sockets supports.");
|
||||
}
|
||||
?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$simple_tcp_server = __DIR__ . "/../include/api/swoole_server/simple_server.php";
|
||||
start_server($simple_tcp_server, TCP_SERVER_HOST, TCP_SERVER_PORT);
|
||||
|
||||
suicide(1000);
|
||||
|
||||
$cli = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
|
||||
$cli->on("connect", function(swoole_client $cli) {
|
||||
// getSocket BUG
|
||||
$cli->getSocket();
|
||||
$cli->getSocket();
|
||||
|
||||
echo "SUCCESS";
|
||||
/*
|
||||
@$cli->getSocket();
|
||||
$err = error_get_last();
|
||||
assert($err["message"] === "swoole_client_async::getSocket(): unable to obtain socket family Error: Bad file descriptor[9].");
|
||||
*/
|
||||
swoole_event_exit();
|
||||
});
|
||||
|
||||
$cli->on("receive", function(swoole_client $cli, $data){});
|
||||
$cli->on("error", function(swoole_client $cli) {echo "error\n";});
|
||||
$cli->on("close", function(swoole_client $cli) {});
|
||||
|
||||
$cli->connect(TCP_SERVER_HOST, TCP_SERVER_PORT, 1);
|
||||
Swoole\Event::wait();
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
SUCCESS
|
68
vendor/swoole/tests/swoole_client_async/getpeername.phpt
vendored
Executable file
68
vendor/swoole/tests/swoole_client_async/getpeername.phpt
vendored
Executable file
@ -0,0 +1,68 @@
|
||||
--TEST--
|
||||
swoole_client: getsockpeername
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$pm = new ProcessManager;
|
||||
$pm->parentFunc = function ($pid)
|
||||
{
|
||||
$cli = new \swoole_client(SWOOLE_SOCK_UDP, SWOOLE_SOCK_ASYNC);
|
||||
|
||||
$cli->on("connect", function (\swoole_client $cli) {
|
||||
assert($cli->isConnected() === true);
|
||||
$cli->send("test");
|
||||
});
|
||||
|
||||
$cli->on("receive", function(\swoole_client $cli, $data){
|
||||
$i = $cli->getpeername();
|
||||
assert($i !== false);
|
||||
$cli->send('shutdown');
|
||||
$cli->close();
|
||||
});
|
||||
|
||||
$cli->on("close", function(\swoole_client $cli) {
|
||||
echo "SUCCESS\n";
|
||||
});
|
||||
|
||||
$r = $cli->connect(UDP_SERVER_HOST, UDP_SERVER_PORT, 1);
|
||||
assert($r);
|
||||
Swoole\Event::wait();
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm)
|
||||
{
|
||||
$serv = new \swoole_server(UDP_SERVER_HOST, UDP_SERVER_PORT, SWOOLE_BASE, SWOOLE_SOCK_UDP);
|
||||
$serv->set(["worker_num" => 1, 'log_file' => '/dev/null']);
|
||||
$serv->on("WorkerStart", function (\swoole_server $serv) use ($pm)
|
||||
{
|
||||
$pm->wakeup();
|
||||
});
|
||||
$serv->on("Packet", function (\swoole_server $serv, $data, $clientInfo)
|
||||
{
|
||||
if (trim($data) == 'shutdown')
|
||||
{
|
||||
$serv->shutdown();
|
||||
return;
|
||||
}
|
||||
$serv->sendto($clientInfo['address'], $clientInfo['port'], $data);
|
||||
});
|
||||
$serv->start();
|
||||
};
|
||||
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
SUCCESS
|
53
vendor/swoole/tests/swoole_client_async/getsockname.phpt
vendored
Executable file
53
vendor/swoole/tests/swoole_client_async/getsockname.phpt
vendored
Executable file
@ -0,0 +1,53 @@
|
||||
--TEST--
|
||||
swoole_client: swoole_client getsockname
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$simple_tcp_server = __DIR__ . "/../include/api/swoole_server/simple_server.php";
|
||||
start_server($simple_tcp_server, TCP_SERVER_HOST, TCP_SERVER_PORT);
|
||||
|
||||
suicide(5000);
|
||||
|
||||
|
||||
$cli = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
|
||||
$cli->on("connect", function(swoole_client $cli) {
|
||||
assert($cli->isConnected() === true);
|
||||
|
||||
$i = $cli->getsockname();
|
||||
assert($i !== false);
|
||||
assert($i["host"] === "127.0.0.1");
|
||||
|
||||
$cli->close();
|
||||
});
|
||||
|
||||
$cli->on("receive", function(swoole_client $cli, $data){
|
||||
});
|
||||
|
||||
$cli->on("error", function(swoole_client $cli) {
|
||||
echo "error";
|
||||
});
|
||||
|
||||
$cli->on("close", function(swoole_client $cli) {
|
||||
echo "SUCCESS";
|
||||
swoole_event_exit();
|
||||
});
|
||||
|
||||
$cli->connect(TCP_SERVER_HOST, TCP_SERVER_PORT, 1);
|
||||
Swoole\Event::wait();
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
SUCCESS
|
135
vendor/swoole/tests/swoole_client_async/length_protocol.phpt
vendored
Executable file
135
vendor/swoole/tests/swoole_client_async/length_protocol.phpt
vendored
Executable file
@ -0,0 +1,135 @@
|
||||
--TEST--
|
||||
swoole_client: length protocol [async]
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$pm = new ProcessManager;
|
||||
$pm->parentFunc = function ($pid)
|
||||
{
|
||||
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
$client->set([
|
||||
'open_length_check' => true,
|
||||
'package_max_length' => 1024 * 1024,
|
||||
'package_length_type' => 'N',
|
||||
'package_length_offset' => 0,
|
||||
'package_body_offset' => 4,
|
||||
]);
|
||||
|
||||
$client->on("connect", function (swoole_client $cli)
|
||||
{
|
||||
$cli->send("recv\r\n\r\n");
|
||||
});
|
||||
|
||||
$client->on("receive", function(swoole_client $cli, $pkg) use ($pid) {
|
||||
static $i = 0;
|
||||
$i++;
|
||||
|
||||
//小包
|
||||
if ($i <= 1000)
|
||||
{
|
||||
assert($pkg and strlen($pkg) <= 2048);
|
||||
if ($i == 1000)
|
||||
{
|
||||
echo "SUCCESS\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
//慢速发送
|
||||
elseif ($i <= 1100)
|
||||
{
|
||||
assert($pkg and strlen($pkg) <= 8192);
|
||||
if ($i == 1100)
|
||||
{
|
||||
echo "SUCCESS\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
//大包
|
||||
else
|
||||
{
|
||||
assert($pkg != false);
|
||||
$_pkg = unserialize(substr($pkg, 4));
|
||||
assert(is_array($_pkg));
|
||||
assert($_pkg['i'] == $i - 1100 - 1);
|
||||
assert($_pkg['data'] <= 256 * 1024);
|
||||
if ($i == 2100) {
|
||||
echo "SUCCESS\n";
|
||||
$cli->close();
|
||||
swoole_process::kill($pid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$client->on("error", function(swoole_client $cli) {
|
||||
print("error");
|
||||
});
|
||||
|
||||
$client->on("close", function(swoole_client $cli) {
|
||||
swoole_event_exit();
|
||||
});
|
||||
|
||||
if (!$client->connect('127.0.0.1', 9501, 0.5, 0))
|
||||
{
|
||||
echo "Over flow. errno=" . $client->errCode;
|
||||
die("\n");
|
||||
}
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm)
|
||||
{
|
||||
$serv = new swoole_server("127.0.0.1", 9501, SWOOLE_BASE);
|
||||
$serv->set(array(
|
||||
"worker_num" => 1,
|
||||
'send_yield' => true,
|
||||
'log_file' => '/tmp/swoole.log',
|
||||
));
|
||||
$serv->on("WorkerStart", function (\swoole_server $serv) use ($pm)
|
||||
{
|
||||
$pm->wakeup();
|
||||
});
|
||||
$serv->on('receive', function (swoole_server $serv, $fd, $rid, $data)
|
||||
{
|
||||
//小包
|
||||
for ($i = 0; $i < 1000; $i++)
|
||||
{
|
||||
$data = str_repeat('A', rand(100, 2000));
|
||||
$serv->send($fd, pack('N', strlen($data)) . $data);
|
||||
}
|
||||
//慢速发送
|
||||
for ($i = 0; $i < 100; $i++)
|
||||
{
|
||||
$data = str_repeat('A', rand(3000, 6000));
|
||||
$n = rand(1000, 2000);
|
||||
$serv->send($fd, pack('N', strlen($data)). substr($data, 0, $n));
|
||||
usleep(rand(10000, 50000));
|
||||
$serv->send($fd, substr($data, $n));
|
||||
}
|
||||
//大包
|
||||
for ($i = 0; $i < 1000; $i++)
|
||||
{
|
||||
$data = serialize(['i' => $i, 'data' => str_repeat('A', rand(20000, 256 * 1024))]);
|
||||
$serv->send($fd, pack('N', strlen($data)) . $data);
|
||||
}
|
||||
});
|
||||
$serv->start();
|
||||
};
|
||||
|
||||
$pm->async = true;
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
--EXPECT--
|
||||
SUCCESS
|
||||
SUCCESS
|
||||
SUCCESS
|
78
vendor/swoole/tests/swoole_client_async/sendfile.phpt
vendored
Executable file
78
vendor/swoole/tests/swoole_client_async/sendfile.phpt
vendored
Executable file
@ -0,0 +1,78 @@
|
||||
--TEST--
|
||||
swoole_client: async sendfile
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$port = get_one_free_port();
|
||||
|
||||
$pm = new ProcessManager;
|
||||
$pm->parentFunc = function ($pid) use ($port)
|
||||
{
|
||||
$client = new Swoole\Client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
$client->on("connect", function (Swoole\Client $cli)
|
||||
{
|
||||
$cli->send(pack('N', filesize(TEST_IMAGE)));
|
||||
$ret = $cli->sendfile(TEST_IMAGE);
|
||||
assert($ret);
|
||||
});
|
||||
$client->on("receive", function (Swoole\Client $cli, $data)
|
||||
{
|
||||
$cli->send(pack('N', 8) . 'shutdown');
|
||||
$cli->close();
|
||||
assert($data === md5_file(TEST_IMAGE));
|
||||
});
|
||||
$client->on("error", function($cli){
|
||||
echo "Connect failed\n";
|
||||
});
|
||||
$client->on("close", function($cli){
|
||||
|
||||
});
|
||||
$client->connect(TCP_SERVER_HOST, $port, 0.5);
|
||||
Swoole\Event::wait();
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm, $port)
|
||||
{
|
||||
$serv = new \swoole_server(TCP_SERVER_HOST, $port, SWOOLE_BASE, SWOOLE_SOCK_TCP);
|
||||
$serv->set([
|
||||
"worker_num" => 1,
|
||||
'log_file' => '/dev/null',
|
||||
'open_length_check' => true,
|
||||
'dispatch_mode' => 1,
|
||||
'package_length_type' => 'N',
|
||||
'package_length_offset' => 0,
|
||||
'package_body_offset' => 4,
|
||||
'package_max_length' => 2000000,
|
||||
]);
|
||||
$serv->on("WorkerStart", function (\swoole_server $serv) use ($pm)
|
||||
{
|
||||
$pm->wakeup();
|
||||
});
|
||||
$serv->on("Receive", function (\swoole_server $serv, $fd, $rid, $data)
|
||||
{
|
||||
if (substr($data, 4, 8) == 'shutdown')
|
||||
{
|
||||
$serv->shutdown();
|
||||
return;
|
||||
}
|
||||
$serv->send($fd, md5(substr($data, 4)));
|
||||
});
|
||||
$serv->start();
|
||||
};
|
||||
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
--EXPECT--
|
66
vendor/swoole/tests/swoole_client_async/sleep_wake.phpt
vendored
Executable file
66
vendor/swoole/tests/swoole_client_async/sleep_wake.phpt
vendored
Executable file
@ -0,0 +1,66 @@
|
||||
--TEST--
|
||||
swoole_client: swoole_client sleep & sleep
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$pm = new ProcessManager;
|
||||
$pm->parentFunc = function ($pid)
|
||||
{
|
||||
$cli = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
|
||||
$cli->on("connect", function (swoole_client $cli)
|
||||
{
|
||||
assert($cli->isConnected() === true);
|
||||
$r = $cli->sleep();
|
||||
assert($r);
|
||||
swoole_timer_after(200, function () use ($cli)
|
||||
{
|
||||
$r = $cli->wakeup();
|
||||
assert($r);
|
||||
});
|
||||
$cli->send(RandStr::gen(1024, RandStr::ALL));
|
||||
});
|
||||
|
||||
$cli->on("receive", function(swoole_client $cli, $data){
|
||||
$recv_len = strlen($data);
|
||||
$cli->send(RandStr::gen(1024, RandStr::ALL));
|
||||
$cli->close();
|
||||
assert($cli->isConnected() === false);
|
||||
});
|
||||
|
||||
$cli->on("error", function(swoole_client $cli) {
|
||||
echo "error";
|
||||
});
|
||||
|
||||
$cli->on("close", function(swoole_client $cli) {
|
||||
echo "SUCCESS";
|
||||
});
|
||||
|
||||
$cli->connect('127.0.0.1', 9501, 0.1);
|
||||
swoole_event::wait();
|
||||
swoole_process::kill($pid);
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm)
|
||||
{
|
||||
include __DIR__ . "/../include/api/tcp_server.php";
|
||||
};
|
||||
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
SUCCESS
|
57
vendor/swoole/tests/swoole_client_async/swoole_client.phpt
vendored
Executable file
57
vendor/swoole/tests/swoole_client_async/swoole_client.phpt
vendored
Executable file
@ -0,0 +1,57 @@
|
||||
--TEST--
|
||||
swoole_client: swoole_client connect & send & close
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$simple_tcp_server = __DIR__ . "/../include/api/swoole_server/simple_server.php";
|
||||
start_server($simple_tcp_server, TCP_SERVER_HOST, TCP_SERVER_PORT);
|
||||
|
||||
|
||||
suicide(5000);
|
||||
|
||||
$cli = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
|
||||
|
||||
$cli->on("connect", function(swoole_client $cli) {
|
||||
assert($cli->isConnected() === true);
|
||||
$cli->send(RandStr::gen(1024, RandStr::ALL));
|
||||
});
|
||||
|
||||
$cli->on("receive", function(swoole_client $cli, $data){
|
||||
$recv_len = strlen($data);
|
||||
// print("receive: len $recv_len");
|
||||
$cli->send(RandStr::gen(1024, RandStr::ALL));
|
||||
$cli->close();
|
||||
assert($cli->isConnected() === false);
|
||||
});
|
||||
|
||||
$cli->on("error", function(swoole_client $cli) {
|
||||
// swoole_timer_clear($cli->timeo_id);
|
||||
print("error");
|
||||
});
|
||||
|
||||
$cli->on("close", function(swoole_client $cli) {
|
||||
// swoole_timer_clear($cli->timeo_id);
|
||||
// print("close");
|
||||
swoole_event_exit();
|
||||
echo "SUCCESS";
|
||||
});
|
||||
|
||||
$cli->connect(TCP_SERVER_HOST, TCP_SERVER_PORT, 0.2);
|
||||
|
||||
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
SUCCESS
|
Reference in New Issue
Block a user