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,21 @@
<?php
require_once __DIR__ . "/../../../include/bootstrap.php";
//swoole_function swoole_timer_after($ms, $callback, $param = null) {}
//swoole_function swoole_timer_tick($ms, $callback) {}
//swoole_function swoole_timer_clear($timer_id) {}
function after()
{
$start = microtime(true);
swoole_timer_after(1000, function() use($start) {
echo microtime(true) - $start, "\n";
after();
});
}
//for ($i = 0; $i < 10000; $i++) {
after();
//}

View File

@ -0,0 +1,79 @@
<?php
function fixRate(callable $callable, $interval)
{
return swoole_timer_tick($interval, $callable);
}
function fixDelay(callable $callable, $interval)
{
return swoole_timer_after($interval, function() use($callable, $interval) {
call_user_func($callable);
fixDelay($callable, $interval);
});
}
function randBlock()
{
$n = mt_rand(0, 10);
for ($i = 0; $i < 1000000 * $n; $i++) {}
}
/*
$t = microtime(true);
fixDelay(swoole_function() use(&$t) {
echo number_format(microtime(true) - $t, 3), PHP_EOL;
randBlock();
$t = microtime(true);
}, 1000);
//*/
/*
1.007
1.005
1.005
1.004
1.003
1.004
1.002
1.006
1.006
1.005
1.004
1.002
1.006
1.004
1.002
*/
/*
$t = microtime(true);
fixRate(swoole_function() use(&$t) {
echo number_format(microtime(true) - $t, 3), PHP_EOL;
randBlock();
$t = microtime(true);
}, 1000);
*/
/*
1.003
0.759
1.005
0.538
1.002
1.003
0.763
1.005
0.247
1.004
1.004
0.270
1.005
0.199
1.000
0.335
1.005
1.006
0.239
1.004
0.119
*/

View File

@ -0,0 +1,26 @@
<?php
require_once __DIR__ . "/../../../include/bootstrap.php";
//swoole_function swoole_timer_after($ms, $callback, $param = null) {}
//swoole_function swoole_timer_tick($ms, $callback) {}
//swoole_function swoole_timer_clear($timer_id) {}
swoole_timer_after(-1, function(){ });
swoole_timer_tick(-1, function() { });
swoole_timer_after(86400001, function(){ });
swoole_timer_tick(86400001, function() { });
swoole_timer_clear(-1);
for ($i = 0; $i < 1000; $i++) {
swoole_timer_clear(swoole_timer_after(1, function() {}));
}
//swoole_timer_after(1, null);
//swoole_timer_after(1, "strlen");
function sw_timer_pass_ref(&$ref_func) {
swoole_timer_after(1, $ref_func);
}
$func = function() {};
sw_timer_pass_ref($func);

View File

@ -0,0 +1,9 @@
<?php
require_once __DIR__ . "/../../../include/bootstrap.php";
for ($j = 0; $j < 100; $j++) {
swoole_timer_after(1, function() use($j){
echo $j, "\n";
});
}

View File

@ -0,0 +1,86 @@
<?php
// first shutdown func
// timer after
function func1()
{
register_shutdown_function(function() {
echo "first shutdown func\n";
});
// $start = microtime(true);
swoole_timer_after(1, function() /*use($start)*/ {
echo "timer after\n";
// echo (microtime(true) - $start) * 1000 - 1;
});
}
// first shutdown func
// timer after
function func1_2()
{
$order4 = function() { echo "first shutdown func\n"; };
$order5 = function() { swoole_event_wait(); };
$order6 = function() { echo "timer after\n";};
// order 1
register_shutdown_function($order4);
// order 2
register_shutdown_function($order5);
// order 3
swoole_timer_after(1, $order6);
}
// timer after
// first shutdown func
function func2()
{
register_shutdown_function(function() {
echo "first shutdown func\n";
});
swoole_timer_after(1, function() {
echo "timer after\n";
});
swoole_event_wait();
}
// first shutdown func
// timer after
// second shutdown func
function func3()
{
register_shutdown_function(function() {
echo "first shutdown func\n";
});
swoole_timer_after(1, function() {
echo "timer after\n";
register_shutdown_function(function() {
echo "second shutdown func\n";
});
});
}
function recv_shutdow()
{
register_shutdown_function(function() {
echo "shutdown\n";
recv_shutdow();
});
}
//recv_shutdow();
//func1();
func1_2();
//func2();
//func3();