初始化

This commit is contained in:
2026-01-06 13:37:07 +08:00
parent c3435595fe
commit 00d7a381aa
70 changed files with 3913 additions and 1 deletions

41
src/Ipc.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
namespace think\worker;
class Ipc
{
protected $workerId;
public function __construct(protected Manager $manager, protected Conduit $conduit)
{
}
public function listenMessage()
{
$this->subscribe();
return $this->workerId;
}
public function sendMessage($workerId, $message)
{
if ($workerId === $this->workerId) {
$this->manager->triggerEvent('message', $message);
} else {
$this->publish($workerId, $message);
}
}
public function subscribe()
{
$this->workerId = $this->conduit->inc('ipc:worker');
$this->conduit->subscribe("ipc:message:{$this->workerId}", function ($message) {
$this->manager->triggerEvent('message', unserialize($message));
});
}
public function publish($workerId, $message)
{
$this->conduit->publish("ipc:message:{$workerId}", serialize($message));
}
}