You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are only 3 items in the documentation for shared memory, these are swole tables, locks, and atomics. I have a situation where I need to accept a request and then send this data to a process that makes requests to third-party services. Next, I need to get a response from these third-party services, but in the current reality, this can only be done through swoole tables and a while loop.
The question is, will there be something like this in the future, or is there already a solution now?
Example
Server
private function initData(): void
{
$socketPath = config('unix-socket-config.socket_file_path');
$this->server = new Server($socketPath, 9501, SWOOLE_PROCESS, SWOOLE_UNIX_DGRAM);
$this->initProcess();
Co::set(['hook_flags' => SWOOLE_HOOK_ALL]);
$this->server->set([
'worker_num' => 1,
'daemonize' => false,
'log_file' => config('unix-socket-config.socket_log_file'),
'enable_coroutine' => true,
'dispatch_mode' => 1,
]);
$this->server->on('Packet', function (Server $server, string $data, array $address) {
$socket = $this->process->exportSocket();
$tracing = bin2hex(random_bytes(10));
dump("rec_dara: $data");
dump("sleep_sec: 10-$data");
$this->data[$tracing] = new Channel(1);
$socket->send($tracing);
$response = $this->data[$tracing]->pop();
var_dump($response);
$server->send($address['address'], "success");
});
$this->server->addProcess($this->process);
}
private function initProcess(): void
{
$this->process = new Process(
callback: function (Process $process) {
dump(ContextManager::get('test'));
$socket = $process->exportSocket();
while (true) {
$key = $socket->recv();
$message = "received-$key";
$this->data[$key]->push($message); //but here will be an exception due to key not exist
}
},
pipe_type: 1,
enable_coroutine: true
);
}
There are only 3 items in the documentation for shared memory, these are swole tables, locks, and atomics. I have a situation where I need to accept a request and then send this data to a process that makes requests to third-party services. Next, I need to get a response from these third-party services, but in the current reality, this can only be done through swoole tables and a while loop.
The question is, will there be something like this in the future, or is there already a solution now?
Example
Server
Swoole 6
Gcc version 13.2.1 20240309 (Alpine 13.2.1_git20240309)
PHP 8.4.1 (cli)
The text was updated successfully, but these errors were encountered: