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

View File

@ -0,0 +1,52 @@
--TEST--
swoole_http_server: http chunk
--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/lib/curl.php';
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) {
$data = curlGet('http://127.0.0.1:9501/');
assert(!empty($data));
assert(md5($data) === md5_file(TEST_IMAGE));
swoole_process::kill($pid);
};
$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
$http->set([
//'log_file' => '/dev/null',
]);
$http->on("WorkerStart", function ($serv, $wid) {
global $pm;
$pm->wakeup();
});
$http->on("request", function ($request, $response) {
$data = str_split(file_get_contents(TEST_IMAGE), 8192);
foreach ($data as $chunk)
{
$response->write($chunk);
}
$response->end();
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--

View File

@ -0,0 +1,97 @@
--TEST--
swoole_http_server: cookies
--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/lib/curl.php';
$cookies = array (
'8MLP_5753_saltkey' => 'RSU8HYED',
'8MLP_5753_lastvisit' => '1426120671',
'attentiondomain' => '2z.cn,chinaz.com,kuaishang.cn,cxpcms.com',
'8MLP_5753_security_cookiereport' => 'c014Hgufskpv55xgM9UaB/ZZdMrcN0QqBYdcGomTu8OlTDWzTA0z',
'8MLP_5753_ulastactivity' => 'e4a1aRIbgdzoRDd8NlT5CMIwLnWjyjr2hWyfn6T5g82RitUOdf3o',
'mytool_user' => 'uSHVgCUFWf5Sv2Y8tKytQRUJW3wMVT3rw5xQLNGQFIsod4C6vYWeGA==',
'PHPSESSID' => 't3hp9h4o8rb3956t5pajnsfab1',
'8MLP_5753_st_p' => '1024432|1428040399|f7599ba9053aa27e12e9e597a4c372ce',
'8MLP_5753_st_t' => '1024432|1428040402|46d40e02d899b10b431822eb1d39f6a1',
'8MLP_5753_forum_lastvisit' => 'D_140_1427103032D_165_1427427405D_168_1427870172D_167_1427870173D_166_1428021390D_163_1428040402',
'8MLP_5753_sid' => 'k25gxK',
'cmstop_page-view-mode' => 'view',
'cmstop_rememberusername' => 'error',
'cmstop_auth' => 'Jcn2qzVn9nsjqtodER9OphcW3PURDWNx6mO7j0Zbb9k=',
'cmstop_username' => 'error',
'Hm_lvt_aecc9715b0f5d5f7f34fba48a3c511d6' => '1427967317,1428021376,1428036617,1428040224',
'Hm_lpvt_aecc9715b0f5d5f7f34fba48a3c511d6' => '1428050417',
'YjVmNm_timeout' => '0',
);
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) use ($cookies) {
$client = new swoole_client(SWOOLE_SOCK_TCP);
if (!$client->connect('127.0.0.1', 9501, 1))
{
exit("connect failed. Error: {$client->errCode}\n");
}
$header = "GET /index.php HTTP/1.1\r\n";
$header .= "Host: 127.0.0.1\r\n";
$header .= "Connection: keep-alive\r\n";
$header .= "Cache-Control: max-age=0\r\n";
$cookieStr = '';
foreach($cookies as $k => $v)
{
$cookieStr .= "$k=$v; ";
}
$cookieStr .= "end=1";
$cookies['end'] = "1";
$header .= "Cookie: $cookieStr\r\n";
$header .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n";
$header .= "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36\r\n";
$header .= "\r\n";
$_sendStr = $header;
$client->send($_sendStr);
$data = $client->recv();
$client->close();
list(, $_respCookieStr) = explode("\r\n\r\n", $data);
$respCookie = json_decode($_respCookieStr, true);
assert($respCookie == $cookies);
swoole_process::kill($pid);
};
$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
$http->set(['log_file' => '/dev/null']);
$http->on("WorkerStart", function ($serv, $wid) {
global $pm;
$pm->wakeup();
});
$http->on("request", function ($request, $response) {
$response->end(json_encode($request->cookie));
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--

View File

@ -0,0 +1,44 @@
--TEST--
enable_coroutine: enable_coroutine setting in server
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require_once __DIR__ . '/../include/bootstrap.php';
require_once __DIR__ . '/../include/lib/curl.php';
use Swoole\Http\Request;
use Swoole\Http\Response;
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) {
echo curlGet('http://127.0.0.1:9501/') . "\n";
echo curlGet('http://127.0.0.1:9501/co') . "\n";
echo curlGet('http://127.0.0.1:9501/co') . "\n";
echo curlGet('http://127.0.0.1:9501/co') . "\n";
swoole_process::kill($pid);
};
$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server('127.0.0.1', 9501);
$http->set([
'enable_coroutine' => false, // close build-in coroutine
'log_level' => -1
]);
$http->on("request", function (Request $request, Response $response) {
$response->header("Content-Type", "text/plain");
if ($request->server['request_uri'] == '/co') {
go(function () use ($response) {
$response->end(Co::getuid());
});
} else {
$response->end(Co::getuid());
}
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--
-1
1
2
3

View File

@ -0,0 +1,28 @@
--TEST--
swoole_http_server: gzip
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require_once __DIR__ . '/../include/bootstrap.php';
require_once __DIR__ . '/../include/swoole.inc';
require_once __DIR__ . '/../include/lib/curl.php';
$pm = new ProcessManager;
$pm->parentFunc = function ($pid)
{
$data = curlGet("http://127.0.0.1:9501/gzip");
assert(md5_file(__DIR__ . '/../../README.md') == md5($data));
swoole_process::kill($pid);
};
$pm->childFunc = function () use ($pm)
{
include __DIR__ . "/../include/api/http_server.php";
};
$pm->childFirst();
$pm->run();
?>
--EXPECTREGEX--

View File

@ -0,0 +1,75 @@
--TEST--
swoole_http_server: large url
--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/lib/curl.php';
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) {
$client = new swoole_client(SWOOLE_SOCK_TCP);
$client->set(array(
'open_tcp_nodelay' => true,
));
if (!$client->connect('127.0.0.1', 9501, 1))
{
exit("connect failed. Error: {$client->errCode}\n");
}
$len = rand(1024, 2048);
$header = "GET /home/explore/?a=".str_repeat('A', $len)." HTTP/1.1\r\n";
$header .= "Host: 127.0.0.1\r\n";
$header .= "Connection: keep-alive\r\n";
$header .= "Cache-Control: max-age=0\r\n";
$cookie = "8MLP_5753_saltkey=RSU8HYED; 8MLP_5753_lastvisit=1426120671; pgv_pvi=1454765056; CNZZDATA1000008050=684878078-1426123263-http%253A%252F%252Fcznews-team.chinaz.com%252F%7C1426485386; attentiondomain=2z.cn%2cchinaz.com%2ckuaishang.cn%2ccxpcms.com; CNZZDATA33217=cnzz_eid%3D1036784254-1426122273-http%253A%252F%252Fcznews-team.chinaz.com%252F%26ntime%3D1427414208; CNZZDATA433095=cnzz_eid%3D1613871160-1426123273-http%253A%252F%252Fcznews-team.chinaz.com%252F%26ntime%3D1427848205; CNZZDATA1254679775=309722566-1427851758-http%253A%252F%252Fcznews-team.chinaz.com%252F%7C1427851758; 8MLP_5753_security_cookiereport=c014Hgufskpv55xgM9UaB%2FZZdMrcN0QqBYdcGomTu8OlTDWzTA0z; 8MLP_5753_ulastactivity=e4a1aRIbgdzoRDd8NlT5CMIwLnWjyjr2hWyfn6T5g82RitUOdf3o; 8MLP_5753_auth=9351LJpv7Xa%2FPUylJDQgRiAONZ5HysOaj%2BqRGb6jYmpqZpRkVc2ibPXm7LAfArC%2FpIpY2Fx%2B59AHqzr843qozZWxWNZi; mytool_user=uSHVgCUFWf5Sv2Y8tKytQRUJW3wMVT3rw5xQLNGQFIsod4C6vYWeGA==; 8MLP_5753_lip=220.160.111.22%2C1428036585; pgv_si=s4245709824; PHPSESSID=t3hp9h4o8rb3956t5pajnsfab1; 8MLP_5753_st_p=1024432%7C1428040399%7Cf7599ba9053aa27e12e9e597a4c372ce; 8MLP_5753_viewid=tid_7701248; 8MLP_5753_smile=5D1; 8MLP_5753_st_t=1024432%7C1428040402%7C46d40e02d899b10b431822eb1d39f6a1; 8MLP_5753_forum_lastvisit=D_140_1427103032D_165_1427427405D_168_1427870172D_167_1427870173D_166_1428021390D_163_1428040402; 8MLP_5753_sid=k25gxK; 8MLP_5753_lastact=1428040403%09misc.php%09patch; cmstop_page-view-mode=view; cmstop_rememberusername=error; cmstop_auth=Jcn2qzVn9nsjqtodER9OphcW3PURDWNx6mO7j0Zbb9k%3D; cmstop_userid=6; cmstop_username=error; Hm_lvt_aecc9715b0f5d5f7f34fba48a3c511d6=1427967317,1428021376,1428036617,1428040224; Hm_lpvt_aecc9715b0f5d5f7f34fba48a3c511d6=1428050417; YjVmNm_timeout=0";
$header .= "Cookie: $cookie\r\n";
$header .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n";
$header .= "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36\r\n";
$header .= "\r\n";
$_sendStr = $header;
$client->send(substr($_sendStr, 0, 512));
usleep(200000);
$client->send(substr($_sendStr, 512, 512));
usleep(200000);
$client->send(substr($_sendStr, 1024));
$data = $client->recv();
$client->close();
assert(!empty($data) and $data = 4096);
swoole_process::kill($pid);
};
$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
$http->set(['log_file' => '/dev/null']);
$http->on("WorkerStart", function ($serv, $wid) {
global $pm;
$pm->wakeup();
});
$http->on("request", function ($request, $response) {
$response->header("Content-Type", "text/plain");
$response->end(strlen($request->get['a']));
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--

View File

@ -0,0 +1,30 @@
--TEST--
swoole_http_response: rawcontent
--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_http_client/simple_http_client.php';
$simple_http_server = __DIR__ . "/../include/api/swoole_http_server/simple_http_server.php";
$closeServer = start_server($simple_http_server, HTTP_SERVER_HOST, $port = get_one_free_port());
$payload = RandStr::gen(1024 * 1024);
testRawcontent(HTTP_SERVER_HOST, $port, $payload, function(\swoole_http_client $cli) use($closeServer, $payload) {
assert($cli->body === $payload);
echo "SUCCESS\n";
$closeServer();
});
swoole_event::wait();
?>
--EXPECT--
SUCCESS

View File

@ -0,0 +1,31 @@
--TEST--
swoole_http_response: rawcooki
--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_http_client/simple_http_client.php';
$simple_http_server = __DIR__ . "/../include/api/swoole_http_server/simple_http_server.php";
$closeServer = start_server($simple_http_server, HTTP_SERVER_HOST, $port = get_one_free_port());
$rawcontent = "HELLO";
testRawCookie(HTTP_SERVER_HOST, $port, $rawcontent, function(\swoole_http_client $cli) use($closeServer, $rawcontent) {
assert($cli->headers["set-cookie"] === "rawcontent=$rawcontent");
echo "SUCCESS";
$closeServer();
});
suicide(1000, SIGTERM, $closeServer);
?>
--EXPECT--
SUCCESS

View File

@ -0,0 +1,51 @@
--TEST--
swoole_http_server: http redirect
--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/lib/curl.php';
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) {
$data = curlGet('http://127.0.0.1:9501/');
assert(!empty($data));
assert(md5($data) === md5_file(TEST_IMAGE));
swoole_process::kill($pid);
};
$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
$http->set([
'log_file' => '/dev/null',
'enable_static_handler' => true,
'document_root' => dirname(dirname(__DIR__)) . '/examples/',
]);
$http->on("WorkerStart", function ($serv, $wid) {
global $pm;
$pm->wakeup();
});
$http->on("request", function ($request, swoole_http_response $response) {
if ($request->server['path_info'] == '/') {
$response->redirect('/test.jpg');
}
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--

View File

@ -0,0 +1,32 @@
--TEST--
swoole_http_server: 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';
require_once __DIR__ . '/../include/api/swoole_http_client/simple_http_client.php';
$simple_http_server = __DIR__ . "/../include/api/swoole_http_server/simple_http_server.php";
$closeServer = start_server($simple_http_server, HTTP_SERVER_HOST, $port = get_one_free_port());
testSendfile(HTTP_SERVER_HOST, $port, function(\swoole_http_client $cli) use($closeServer) {
// TODO: !!!! swoole_server send file block
//var_dump($cli);
echo "SUCCESS";
$closeServer();
});
suicide(1000, SIGTERM, $closeServer);
?>
--EXPECT--
SUCCESS

View File

@ -0,0 +1,49 @@
--TEST--
swoole_http_server: cookies
--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/lib/curl.php';
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) {
$data = curlGet('http://127.0.0.1:9501/test.jpg');
assert(!empty($data));
assert(md5($data) === md5_file(TEST_IMAGE));
swoole_process::kill($pid);
};
$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
$http->set([
'log_file' => '/dev/null',
'enable_static_handler' => true,
'document_root' => dirname(dirname(__DIR__)) . '/examples/',
]);
$http->on("WorkerStart", function ($serv, $wid) {
global $pm;
$pm->wakeup();
});
$http->on("request", function ($request, $response) {
$response->end(TEST_IMAGE);
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--

View File

@ -0,0 +1,69 @@
--TEST--
swoole_http_server: cookies
--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/lib/curl.php';
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:9501");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1); //设置为POST方式
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
$file = TEST_IMAGE;
$post_data = array('test' => str_repeat('a', 80));
if (function_exists("curl_file_create"))
{
$cfile = curl_file_create($file);
$post_data['file'] = $cfile;
}
else
{
$post_data['file'] = '@' . $file;
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); //POST数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
assert(!empty($res));
assert($res === md5_file($file));
curl_close($ch);
swoole_process::kill($pid);
};
$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
$http->set(['log_file' => '/dev/null']);
$http->on("WorkerStart", function ($serv, $wid) {
global $pm;
$pm->wakeup();
});
$http->on("request", function ($request, $response) {
$response->end(md5_file($request->files['file']['tmp_name']));
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--

View File

@ -0,0 +1,63 @@
--TEST--
swoole_http_server: upload file
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require_once __DIR__ . '/../include/bootstrap.php';
require_once __DIR__ . '/../include/swoole.inc';
require_once __DIR__ . '/../include/lib/curl.php';
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) use ($pm)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:9501");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
$post_data = array('test' => str_repeat('a', 80));
if (function_exists("curl_file_create"))
{
$cfile = curl_file_create(TEST_IMAGE);
$post_data['upfile'] = $cfile;
}
else
{
$post_data['upfile'] = '@' . TEST_IMAGE;
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); //POST数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
curl_close($ch);
$pm->kill();
};
$pm->childFunc = function () use ($pm)
{
$http = new swoole_http_server("127.0.0.1", 9501);
$http->set(['log_file' => '/dev/null']);
$http->on('workerStart', function() use ($pm) {
$pm->wakeup();
});
$http->on('request', function ($request, $response) {
if (empty($request->files['upfile']) or md5_file(TEST_IMAGE) != md5_file($request->files['upfile']['tmp_name']))
{
$response->end("ERROR");
}
else
{
$response->end("OK");
}
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--
OK