This commit is contained in:
2023-08-28 12:01:30 +08:00
parent 4a607a5687
commit 9b4f5d59dc
7 changed files with 234 additions and 192 deletions
+12
View File
@@ -84,6 +84,18 @@ class ActorManager
} }
/**
* @param array|null $data
* @return void
*/
public static function exec(?array $data): void
{
if (is_null($data)) {
return;
}
}
/** /**
* @return void * @return void
*/ */
+3
View File
@@ -3,6 +3,8 @@ declare(strict_types=1);
namespace Kiri\Actor; namespace Kiri\Actor;
use JetBrains\PhpStorm\ArrayShape;
class ActorMessage implements \JsonSerializable class ActorMessage implements \JsonSerializable
{ {
@@ -63,6 +65,7 @@ class ActorMessage implements \JsonSerializable
/** /**
* @return array * @return array
*/ */
#[ArrayShape(['userId' => "int", 'event' => "string", 'body' => "array"])]
public function jsonSerialize(): array public function jsonSerialize(): array
{ {
return [ return [
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace Kiri\Actor;
use Kiri\Server\Abstracts\BaseProcess;
use Swoole\Coroutine;
use Swoole\Process;
class ActorProcess extends BaseProcess
{
/**
* @var bool
*/
protected bool $enable_coroutine = true;
/**
* @return string
*/
public function getName(): string
{
// TODO: Change the autogenerated stub
return '[' . \config('id', 'system-service') . '].Actor Manager';
}
public function process(?Process $process): void
{
// TODO: Implement process() method.
while ($this->isStop() === false) {
$read = $process->read();
ActorManager::exec(json_decode($read, true));
Coroutine::sleep(1000 / 120);
}
}
/**
* @return $this
*/
public function onSigterm(): static
{
// TODO: Implement onSigterm() method.
Coroutine::create(function () {
$sign = Coroutine::waitSignal(SIGINT | SIGTERM);
if ($sign) {
$this->onShutdown(true);
}
});
return $this;
}
}
+10
View File
@@ -47,6 +47,16 @@ class Component implements Configure
} }
/**
* @return Kiri\Error\StdoutLogger
* @throws \ReflectionException
*/
public function getLogger(): Kiri\Error\StdoutLogger
{
return Kiri::getLogger();
}
/** /**
* @param string $name * @param string $name
* @return mixed * @return mixed
+8 -4
View File
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace Kiri\Error; namespace Kiri\Error;
use Closure; use Closure;
use ErrorException;
use Exception; use Exception;
use Kiri; use Kiri;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
@@ -18,6 +19,7 @@ use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use ReflectionException; use ReflectionException;
use Kiri\Events\OnSystemError; use Kiri\Events\OnSystemError;
use Throwable;
/** /**
* Class ErrorHandler * Class ErrorHandler
@@ -110,13 +112,13 @@ class ErrorHandler extends Component implements ErrorInterface
/** /**
* @param \Throwable $exception * @param Throwable $exception
* *
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws Exception * @throws Exception
*/ */
public function exceptionHandler(\Throwable $exception): void public function exceptionHandler(Throwable $exception): void
{ {
$this->category = 'exception'; $this->category = 'exception';
@@ -127,7 +129,7 @@ class ErrorHandler extends Component implements ErrorInterface
/** /**
* @throws \ErrorException * @throws ErrorException
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ReflectionException * @throws ReflectionException
@@ -136,8 +138,10 @@ class ErrorHandler extends Component implements ErrorInterface
{ {
$error = func_get_args(); $error = func_get_args();
var_dump($error);
event(new OnSystemError()); event(new OnSystemError());
throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]); throw new ErrorException($error[1], $error[0], 1, $error[2], $error[3]);
} }
} }
+9 -12
View File
@@ -1,17 +1,14 @@
<?php <?php
use function Swoole\Coroutine\run;
use Swoole\Runtime; run(function () {
use Swoole\Coroutine\Http\Server;
Runtime::enableCoroutine(true); $channel = new \Swoole\Coroutine\Channel(100);
for ($i = 0; $i < 90; $i++) {
\Co\run(function () { $channel->push(100);
Swoole\Coroutine::create(function () { }
var_dump(1); $channel->close();
}); $channel = null;
$server = new Server('0.0.0.0',9501); var_dump($channel);
$server->handle('/', function () {
});
$server->start();
}); });
+9 -48
View File
@@ -1,52 +1,13 @@
<?php <?php
$i = 0;
namespace Ar; while ($i <= 100) {
for ($ii = 0; $ii < 10; $ii++) {
echo "\r";
$i++;
//require_once "a.php"; echo '[' . $i . '%]' . "\r";
// }
// sleep(1);
//$time = microtime(); }
//
//echo \count([]) . PHP_EOL;
//
//echo $time . PHP_EOL;
//echo microtime() . PHP_EOL;
//
//
//
//$time = microtime();
//
//echo count([]) . PHP_EOL;
//
//echo $time . PHP_EOL;
//echo microtime() . PHP_EOL;
//
use Swoole\Coroutine\Http\Client;
use function Swoole\Coroutine\run;
//run(function () {
//
// $client = new Client('47.92.194.207',8500);
// $client->get('/v1/agent/services?filter=Service == FriendRpcService');
// $client->close();
// var_dump($client->getBody());
//
//});
$spl = new \SplPriorityQueue();
$spl->insert(1,0);
$spl->insert(2,0);
$spl->insert(3,0);
$spl->insert(4,0);
$spl->insert(5,0);
$spl->insert(6,0);
$spl->insert(7,0);
$spl->compare();
$spl->extract();
var_dump($spl);