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,17 @@
--TEST--
enable_coroutine: enable_coroutine setting
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require_once __DIR__ . '/../include/bootstrap.php';
swoole_async_set([
'enable_coroutine' => false
]);
swoole_timer_after(1, function () {
$uid = Co::getuid();
echo "#{$uid}\n";
});
?>
--EXPECT--
#-1

View File

@ -0,0 +1,21 @@
--TEST--
swoole_timer: Timer must be greater than 0
--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';
assert(@swoole_timer_after(0, function() {}) === false);
assert(@swoole_timer_after(-1, function() {}) === false);
assert(@swoole_timer_tick(0, function() {}) === false);
assert(@swoole_timer_tick(-1, function() {}) === false);
?>
--EXPECTF--

View File

@ -0,0 +1,21 @@
--TEST--
swoole_timer: The given parameters is too big.
--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';
assert(@swoole_timer_after(86400001, function() {}) === false);
assert(@swoole_timer_after(86400001, function() {}) === false);
assert(@swoole_timer_tick(86400001, function() {}) === false);
assert(@swoole_timer_tick(86400001, function() {}) === false);
?>
--EXPECTF--

View File

@ -0,0 +1,53 @@
--TEST--
swoole_timer: swoole_timer_after,swoole_timer_exists,swoole_timer_clear
--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';
class TimerTest {
public static $count = 0;
private $timer_id = null;
protected function resetTimer($ms) {
if ($this->timer_id && swoole_timer_exists($this->timer_id)) {
swoole_timer_clear($this->timer_id);
$this->timer_id = null;
}
if (self::$count == 10) {
return;
}
$this->timer_id = swoole_timer_after($ms, array($this, 'onTimerTick'));
assert($this->timer_id > 0);
}
public function onTimerTick() {
self::$count++;
echo "onTimerTick:" . self::$count . "\n";
$this->resetTimer(10);
}
}
$timer_test = new TimerTest();
$timer_test->onTimerTick();
?>
--EXPECT--
onTimerTick:1
onTimerTick:2
onTimerTick:3
onTimerTick:4
onTimerTick:5
onTimerTick:6
onTimerTick:7
onTimerTick:8
onTimerTick:9
onTimerTick:10

View File

@ -0,0 +1,81 @@
--TEST--
swoole_timer: call after in Task-Worker
--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 = 9508;
$pm = new ProcessManager;
$pm->parentFunc = function ($pid) use ($port, $pm)
{
$cli = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
$cli->set(['open_eof_check' => true, "package_eof" => "\r\n\r\n"]);
$cli->connect("127.0.0.1", $port, 5) or die("ERROR");
$cli->send("task-01") or die("ERROR");
for ($i = 0; $i < 4; $i++)
{
echo trim($cli->recv())."\n";
}
$pm->kill();
};
$pm->childFunc = function () use ($pm, $port)
{
ini_set('swoole.display_errors', 'Off');
$serv = new swoole_server("127.0.0.1", $port);
$serv->set(array(
"worker_num" => 1,
'task_worker_num' => 2,
'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->task([$fd, 'timer']);
});
$serv->on('task', function (swoole_server $serv, $task_id, $worker_id, $data) {
list($fd) = $data;
swoole_timer::after(500, function () use ($serv, $fd) {
$serv->send($fd, "500\r\n\r\n");
swoole_timer::after(300, function () use ($serv, $fd) {
$serv->send($fd, "800\r\n\r\n");
});
});
swoole_timer::after(1000, function () use ($serv, $fd) {
$serv->send($fd, "1000\r\n\r\n");
});
swoole_timer::after(2000, function () use ($serv, $fd) {
$serv->send($fd, "2000\r\n\r\n");
});
});
$serv->on('finish', function (swoole_server $serv, $fd, $rid, $data)
{
});
$serv->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--
500
800
1000
2000