easyswoole / component
easyswoole component
Installs: 178 220
Dependents: 72
Suggesters: 0
Security: 0
Stars: 13
Watchers: 1
Forks: 25
Open Issues: 0
Requires
- php: >=7.1.0
- ext-swoole: *
- easyswoole/spl: ^2.0
Requires (Dev)
- easyswoole/phpunit: ^1.0
- easyswoole/swoole-ide-helper: ^1.2
- dev-master
- 2.3.9
- 2.3.8
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.12
- 2.2.11
- 2.2.10
- 2.2.9
- 2.2.8
- 2.2.7
- 2.2.6
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.9
- 1.8.8
- 1.8.7
- 1.8.6
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.6.1
- 1.6.0
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.4.19
- 1.4.18
- 1.4.17
- 1.4.16
- 1.4.15
- 1.4.14
- 1.4.13
- 1.4.12
- 1.4.11
- 1.4.10
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2024-10-22 08:14:34 UTC
README
use EasySwoole\Component\CoroutineRunner\Runner;
use Swoole\Coroutine\Scheduler;
use EasySwoole\Component\CoroutineRunner\Task;
$scheduler = new Scheduler;
$scheduler->add(function () {
$runner = new Runner(4);
$i = 10;
while ($i){
$runner->addTask(new Task(function ()use($runner,$i){
var_dump("now is num.{$i} at time ".time());
\co::sleep(1);
if($i == 5){
$runner->addTask(new Task(function (){
var_dump('this is task add in running');
}));
}
}));
$i--;
}
$runner->start();
var_dump('task finish');
});
$scheduler->start();
PoolInterface Example1
use EasySwoole\Component\Pool\PoolManager;
use EasySwoole\Component\Pool\TraitObjectInvoker;
use EasySwoole\Utility\Random;
use EasySwoole\Component\Pool\AbstractPoolObject;
use EasySwoole\Component\Pool\PoolObjectInterface;
use EasySwoole\Component\Pool\AbstractPool;
class test
{
public $id;
function __construct()
{
$this->id = Random::character(8);
}
function fuck(){
var_dump('this is fuck at class:'.static::class.'@id:'.$this->id);
}
}
class test2 extends test implements PoolObjectInterface
{
function objectRestore()
{
var_dump('this is objectRestore at class:'.static::class.'@id:'.$this->id);
}
function gc()
{
// TODO: Implement gc() method.
}
function beforeUse(): bool
{
// TODO: Implement beforeUse() method.
return true;
}
}
class testPool extends AbstractPool
{
protected function createObject()
{
// TODO: Implement createObject() method.
return new test();
}
}
class testPool2 extends AbstractPool
{
protected function createObject()
{
// TODO: Implement createObject() method.
return new test2();
}
}
class test3 extends test
{
use TraitObjectInvoker;
}
class test4 extends AbstractPoolObject
{
function finalFuck()
{
var_dump('final fuck');
}
function objectRestore()
{
var_dump('final objectRestore');
}
}
//cli下关闭pool的自动定时检查
PoolManager::getInstance()->getDefaultConfig()->setIntervalCheckTime(0);
go(function (){
go(function (){
$object = PoolManager::getInstance()->getPool(test::class)->getObj();
$object->fuck();
PoolManager::getInstance()->getPool(test::class)->recycleObj($object);
});
go(function (){
testPool::invoke(function (test $test){
$test->fuck();
});
});
go(function (){
testPool2::invoke(function (test2 $test){
$test->fuck();
});
});
go(function (){
test3::invoke(function (test3 $test3){
$test3->fuck();
});
});
go(function (){
$object = PoolManager::getInstance()->getPool(test4::class)->getObj();
$object->finalFuck();
PoolManager::getInstance()->getPool(test4::class)->recycleObj($object);
});
});
PoolInterface Example2
use EasySwoole\Component\Pool\PoolManager;
use EasySwoole\Component\Pool\AbstractPool;
use EasySwoole\Component\Pool\TraitInvoker;
class TestPool extends AbstractPool{
function __construct(\EasySwoole\Component\Pool\PoolConf $conf)
{
var_dump('new TestPool');
parent::__construct($conf);
}
protected function createObject()
{
// TODO: Implement createObject() method.
return new \stdClass();
}
}
class TestPool2
{
use TraitInvoker;
function __construct()
{
var_dump('new TestPool2');
}
function fuck()
{
var_dump('fuck');
}
}
go(function (){
PoolManager::getInstance()->registerAnonymous('test',function (){
return new SplFixedArray();
});
$pool = PoolManager::getInstance()->getPool(stdClass::class);
$pool2 = PoolManager::getInstance()->getPool(\Redis::class);
$pool3 = PoolManager::getInstance()->getPool('test');
$pool::invoke(function (stdClass $class){
var_dump($class);
});
$pool2::invoke(function (\Redis $class){
var_dump($class);
});
$pool3::invoke(function (SplFixedArray $array){
var_dump($array);
});
TestPool::invoke(function (\stdClass $class){
// var_dump($class);
});
$pool4 = PoolManager::getInstance()->getPool(TestPool::class);
$pool4::invoke(function (\stdClass $class){
// var_dump($class);
});
TestPool2::invoke(function ($class){
$class->fuck();
});
$pool5 = PoolManager::getInstance()->getPool(TestPool2::class);
$pool5::invoke(function (\TestPool2 $class){
// $class->fuck();
});
});