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

25
vendor/swoole/examples/http/async_client.php vendored Executable file
View File

@ -0,0 +1,25 @@
<?php
$cli = new swoole_http_client('127.0.0.1', 9501);
//post request
//$cli->setData(http_build_query(['a'=>123,'b'=>"哈哈"]));
//$cli->set(['timeout' => -1]);
//$cli->setHeaders(['Host' => 'www.baidu.com']);
//$cli->set(['http_proxy_host' => '127.0.0.1', 'http_proxy_port' => 8888,]);
$cli->setHeaders(['User-Agent' => "swoole"]);
$cli->get('/index.php', function ($cli)
{
var_dump($cli);
});
//$cli->post('/dump.php', array("test" => 'abc'), function ($cli) {
// echo $cli->body;
// $cli->get('/index.php', function ($cli) {
// file_put_contents(__DIR__.'/t.html', $cli->body);
// $cli->download('/index.php', __DIR__.'/phpinfo.html', function ($cli)
// {
// var_dump($cli->downloadFile);
// });
// });
//});

View File

@ -0,0 +1,11 @@
<?php
$cli = new swoole_http_client('127.0.0.1', 9501);
$cli->on('message', function ($_cli, $frame) {
var_dump($frame);
});
$cli->upgrade('/', function ($cli) {
echo $cli->body;
$cli->push("hello world");
});

56
vendor/swoole/examples/http/client.php vendored Executable file
View File

@ -0,0 +1,56 @@
<?php
$cli = new swoole_client(SWOOLE_SOCK_TCP);
$cli->connect('127.0.0.1', 9501);
//$type = 'GET';
$type = 'POST';
$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";
if ($type == 'GET')
{
$header = "GET /home/explore/ 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";
$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;
}
else
{
// $header = "POST /home/explore/?hello=123&world=swoole#hello HTTP/1.1\r\n";
$header = "POST /post.php HTTP/1.1\r\n";
$header .= "Host: 127.0.0.1\r\n";
$header .= "Referer: http://group.swoole.com/\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,ja;q=0.2\r\n";
$header .= "Cookie: pgv_pvi=9559734272; efr__Session=uddfvbm87dtdtrdsro1ohlt4o6; efr_r_uname=apolov%40vip.qq.com; efr__user_login=3N_b4tHW1uXGztWW2Ojf09vssOjR5abS4abO5uWRopnm0eXb7OfT1NbIoqjWzNCvodihq9qaptqfra6imtLXpNTNpduVoque26mniKej5dvM09WMopmmpM2xxcmhveHi3uTN0aegpaiQj8Snoa2IweHP5fCL77CmxqKqmZKp5ejN1c_Q2cPZ25uro6mWqK6BmMOzy8W8k4zi2d3Nlb_G0-PaoJizz97l3deXqKyPoKacr6ynlZ2nppK71t7C4uGarKunlZ-s; pgv_si=s8426935296; Hm_lvt_4967f2faa888a2e52742bebe7fcb5f7d=1410240641,1410241802,1410243730,1410243743; Hm_lpvt_4967f2faa888a2e52742bebe7fcb5f7d=1410248408\r\n";
$header .= "RA-Ver: 2.5.3\r\n";
$header .= "RA-Sid: 2A784AF7-20140212-113827-085a9c-c4de6e\r\n";
$_postData = ['body1' => 'swoole_http-server', 'message' => 'nihao'];
$_postBody = json_encode($_postData);
// $_postBody = http_build_query($_postData);
$header .= "Content-Length: " . strlen($_postBody);
echo "http header length=".strlen($header)."\n";
$header .= "Content-Length: " . (strlen($_postBody) - 2);
// $cli->send($header);
// usleep(100000);
$_sendStr = $header . "\r\n\r\n" . $_postBody;
// $_sendStr = "\r\n\r\n" . $_postBody;
echo "postBody length=".strlen($_postBody)."\n";
}
echo "-------------------------Request----------------------------\n";
echo $_sendStr;
$cli->send($_sendStr);
echo "send ".strlen($_sendStr)." byte\n";
echo "-------------------------Response----------------------------\n";
$data = $cli->recv();
var_dump($data);
exit;

28
vendor/swoole/examples/http/curl.php vendored Executable file
View File

@ -0,0 +1,28 @@
<?php
// 创建一个新cURL资源
$ch = curl_init();
// 设置URL和相应的选项
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:'));
$post_data = array('test' => str_repeat('a', 80));
if (function_exists("curl_file_create"))
{
$cfile = curl_file_create(__DIR__ . '/../test.jpg');
$post_data['file'] = $cfile;
}
else
{
$post_data['file'] = '@' . __DIR__ . '/../test.jpg';
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); //POST数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 抓取URL并把它传递给浏览器
$res = curl_exec($ch);
var_dump($res);
// 关闭cURL资源并且释放系统资源
curl_close($ch);

34
vendor/swoole/examples/http/detach.php vendored Executable file
View File

@ -0,0 +1,34 @@
<?php
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set(['task_worker_num' => 1, 'worker_num' => 1]);
$http->on('request', function ($req, Swoole\Http\Response $resp) use ($http) {
$resp->detach();
$http->task(strval($resp->fd));
});
$http->on('finish', function ()
{
echo "task finish";
});
$http->on('task', function ($serv, $task_id, $worker_id, $data)
{
var_dump($data);
$resp = Swoole\Http\Response::create($data);
$resp->end("in task");
echo "async task\n";
});
//$http->on('close', function(){
// echo "on close\n";
//});
$http->on('workerStart', function ($serv, $id)
{
//var_dump($serv);
});
$http->start();

12
vendor/swoole/examples/http/download.php vendored Executable file
View File

@ -0,0 +1,12 @@
<?php
$fp = fopen (__DIR__. '/test.html', 'w+');
$ch = curl_init("http://127.0.0.1/index.php");
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
// write curl response to file
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// get curl response
curl_exec($ch);
curl_close($ch);
fclose($fp);

25
vendor/swoole/examples/http/http_proxy.php vendored Executable file
View File

@ -0,0 +1,25 @@
<?php
Swoole\Async::dnsLookup("www.htmleaf.com", function ($domainName, $ip) {
//Swoole\Async::dnsLookup("www.baidu.com", function ($domainName, $ip) {
$cli = new swoole_http_client($ip, 80);
//$cli = new swoole_http_client($ip, 443,true);
$cli->set(array(
'http_proxy_host'=>"127.0.0.1",
'http_proxy_port'=>3128,
));
$cli->setHeaders([
'Host' => $domainName,
"User-Agent" => 'Chrome/49.0.2587.3',
]);
$cli->get('/', function ($cli) {
echo "Length: " . strlen($cli->body) . "\n";
$cli->close();
// echo $cli->body;
});
});
?>

View File

@ -0,0 +1,20 @@
<?php
$cli = new swoole_http_client('127.0.0.1', 80);
$cli->set(array(
'http_proxy_host' => "127.0.0.1",
'http_proxy_port' => 33080,
'http_proxy_user' => 'test',
'http_proxy_password' => 'test',
));
$cli->setHeaders([
'Host' => "localhost",
"User-Agent" => 'Chrome/49.0.2587.3',
]);
$cli->get('/', function ($cli) {
echo "Length: " . strlen($cli->body) . ", statusCode=".$cli->statusCode."\n";
$cli->close();
echo $cli->body;
});

21
vendor/swoole/examples/http/https_proxy.php vendored Executable file
View File

@ -0,0 +1,21 @@
<?php
Swoole\Async::dnsLookup("www.baidu.com", function ($domainName, $ip) {
//Swoole\Async::dnsLookup("www.baidu.com", function ($domainName, $ip) {
$cli = new swoole_http_client($ip, 443,true);
$cli->set(array(
'http_proxy_host'=>"127.0.0.1",
'http_proxy_port'=>3128,
));
$cli->setHeaders([
'Host' => $domainName,
"User-Agent" => 'Chrome/49.0.2587.3',
]);
$cli->get('/', function ($cli) {
echo "Length: " . strlen($cli->body) . "\n";
echo $cli->body;
});
});
?>

1
vendor/swoole/examples/http/post.data vendored Executable file
View File

@ -0,0 +1 @@
dd=wwwwww&ddd=eee&3412=3234&hello=world%2C+i+am+rango%2C+thank+you.+no+body

13
vendor/swoole/examples/http/raw.php vendored Executable file
View File

@ -0,0 +1,13 @@
<?php
$sock = stream_socket_client("tcp://127.0.0.1:9501");
fwrite($sock, file_get_contents('httpdata'));
stream_set_chunk_size($sock, 2*1024*1024);
$data = fread($sock, 8192 * 128);
if ($argv[1] == 'save')
{
file_put_contents("resp.html", $data);
}
else
{
echo $data;
}

8
vendor/swoole/examples/http/redirect.php vendored Executable file
View File

@ -0,0 +1,8 @@
<?php
$http = new swoole_http_server("0.0.0.0", 9501, SWOOLE_BASE);
$http->on('request', function ($req, Swoole\Http\Response $resp) {
$resp->redirect("http://www.baidu.com/", 301);
});
$http->start();

213
vendor/swoole/examples/http/server.php vendored Executable file
View File

@ -0,0 +1,213 @@
<?php
function dump($var)
{
return highlight_string("<?php\n\$array = ".var_export($var, true).";", true);
}
$key_dir = dirname(dirname(__DIR__)) . '/tests/ssl';
$http = new swoole_http_server("0.0.0.0", 9501, SWOOLE_BASE);
//$http = new swoole_http_server("0.0.0.0", 9501);
//$http = new swoole_http_server("0.0.0.0", 9501, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
//https
//$http = new swoole_http_server("0.0.0.0", 9501, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
//$http->setGlobal(HTTP_GLOBAL_ALL, HTTP_GLOBAL_GET|HTTP_GLOBAL_POST|HTTP_GLOBAL_COOKIE);
$http->set([
// 'daemonize' => 1,
// 'open_cpu_affinity' => 1,
// 'task_worker_num' => 1,
//'open_cpu_affinity' => 1,
//'task_worker_num' => 100,
//'enable_port_reuse' => true,
// 'worker_num' => 4,
//'log_file' => __DIR__.'/swoole.log',
// 'reactor_num' => 24,
//'dispatch_mode' => 3,
//'discard_timeout_request' => true,
// 'open_tcp_nodelay' => true,
// 'open_mqtt_protocol' => true,
//'task_worker_num' => 1,
//'user' => 'www-data',
//'group' => 'www-data',
//'daemonize' => true,
// 'ssl_cert_file' => $key_dir.'/ssl.crt',
// 'ssl_key_file' => $key_dir.'/ssl.key',
'enable_static_handler' => true,
'document_root' => '/home/htf/workspace/php/www.swoole.com/web/'
]);
$http->listen('127.0.0.1', 9502, SWOOLE_SOCK_TCP);
function chunk(swoole_http_request $request, swoole_http_response $response)
{
$response->write("<h1>hello world1</h1>");
//sleep(1);
$response->write("<h1>hello world2</h1>");
//sleep(1);
$response->end();
}
function no_chunk(swoole_http_request $request, swoole_http_response $response)
{
/**
* Cookie Test
*/
//$response->cookie('test1', '1234', time() + 86400, '/');
// $response->cookie('test2', '5678', time() + 86400);
// var_dump($response->cookie);
// var_dump($request->cookie);
// try
// {
// if (rand(1, 99) % 2 == 1)
// {
// throw new Exception("just for fun.");
// }
// $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
// }
// catch(Exception $e)
// {
// $response->end("<h1>Exceptiom</h1><div>".$e->getMessage()."</div>");
// }
//var_dump($request->server['request_uri'], substr($request->server['request_uri'], -4, 4));
if (substr($request->server['request_uri'], -8, 8) == 'test.jpg')
{
$response->header('Content-Type', 'image/jpeg');
$response->sendfile(dirname(__DIR__).'/test.jpg');
return;
}
if ($request->server['request_uri'] == '/test.txt')
{
$last_modified_time = filemtime(__DIR__ . '/test.txt');
$etag = md5_file(__DIR__ . '/test.txt');
// always send headers
$response->header("Last-Modified", gmdate("D, d M Y H:i:s", $last_modified_time) . " GMT");
$response->header("Etag", $etag);
if (strtotime($request->header['if-modified-since']) == $last_modified_time or trim($request->header['if-none-match']) == $etag)
{
$response->status(304);
$response->end();
}
else
{
$response->sendfile(__DIR__ . '/test.txt');
}
return;
}
if ($request->server['request_uri'] == '/favicon.ico')
{
$response->status(404);
$response->end();
return;
}
if ($request->server['request_uri'] == '/save')
{
file_put_contents(__DIR__.'/httpdata', $request->getData());
$response->end('hello');
return;
}
// else
// {
//var_dump($request->post);
//var_export($request->cookie);
// var_dump($request->rawContent());
// if ($request->server['request_method'] == 'POST')
// {
// var_dump($request->post);
// }
// echo "GET:" . var_export($_GET, true)."\n";
// echo "POST:" . var_export($_POST, true)."\n";
// echo "get:" . var_export($request->get, true)."\n";
// echo "post:" . var_export($request->post, true)."\n";
//var_dump($request->server);
$output = '';
$output .= "<h2>HEADER:</h2>".dump($request->header);
$output .= "<h2>SERVER:</h2>".dump($request->server);
if (!empty($request->files))
{
$output .= "<h2>FILE:</h2>".dump($request->files);
}
if (!empty($request->cookie))
{
$output .= "<h2>COOKIES:</h2>".dump($request->cookie);
}
if (!empty($request->get))
{
$output .= "<h2>GET:</h2>".dump($request->get);
}
if (!empty($request->post))
{
$output .= "<h2>POST:</h2>".dump($request->post);
}
var_dump($request->post);
//$response->header('X-Server', 'Swoole');
//unset($request, $response);
// swoole_timer_after(2000, function() use ( $response) {
$response->end("<h1>Hello Swoole.</h1>".$output);
// });
// }
return;
//var_dump($request);
// var_dump($_GET);
//var_dump($_POST);
//var_dump($_COOKIE);
//$response->status(301);
//$response->header("Location", "http://www.baidu.com/");
//$response->cookie("hello", "world", time() + 3600);
// $response->header("Content-Type", "text/html; charset=utf-8");
//var_dump($request->post);
// var_dump($request->get);
// echo strlen(gzdeflate("<h1>Hello Swoole.</h1>"));
// $response->end("<h1>Hello Swoole.</h1>");
//$response->end("<h1>Hello Swoole. #".str_repeat('A', rand(100, 999))."</h1>");
//global $http;
//$http->task("hello world");
$file = realpath(__DIR__ . '/../' . $request->server['request_uri']);
if (is_file($file))
{
echo "http get file=$file\n";
if (substr($file, -4) == '.php')
{
$response->gzip();
}
else
{
$response->header('Content-Type', 'image/jpeg');
}
$content = file_get_contents($file);
echo "response size = " . strlen($content) . "\n";
// $response->write($content);
// $response->end();
$response->end($content);
}
else
{
$response->end("<h1>Hello Swoole.</h1>");
}
}
$http->on('request', 'no_chunk');
$http->on('finish', function ()
{
echo "task finish";
});
$http->on('task', function ()
{
echo "async task\n";
});
//$http->on('close', function(){
// echo "on close\n";
//});
$http->on('workerStart', function ($serv, $id)
{
//var_dump($serv);
});
$http->start();

1
vendor/swoole/examples/http/test.txt vendored Executable file
View File

@ -0,0 +1 @@
hello world!

11
vendor/swoole/examples/http/upload_file.php vendored Executable file
View File

@ -0,0 +1,11 @@
<?php
$cli = new swoole_http_client('127.0.0.1', 80);
//post request
$cli->setHeaders(['User-Agent' => "swoole"]);
$cli->addFile(__DIR__.'/post.data', 'post');
$cli->addFile(dirname(__DIR__).'/test.jpg', 'debug');
$cli->post('/dump2.php', array("xxx" => 'abc', 'x2' => 'rango'), function ($cli) {
echo $cli->body;
$cli->close();
});