Closed 1107012776 closed 2 years ago
https://www.easyswoole.com/Components/Component/template.html 按文档这边的弄,感觉会有协程安全问题
public function run($arg)
{
if (file_exists($this->getConfig()->getSocketFile()))
{
unlink($this->getConfig()->getSocketFile());
}
$socketServer = new Socket(AF_UNIX,SOCK_STREAM,0);
$socketServer->setOption(SOL_SOCKET,SO_LINGER,$this->getConfig()->getLinger());
if(!$socketServer->bind($this->getConfig()->getSocketFile())){
throw new Exception(static::class.' bind '.$this->getConfig()->getSocketFile(). ' fail case '.$socketServer->errMsg);
}
if(!$socketServer->listen(2048)){
throw new Exception(static::class.' listen '.$this->getConfig()->getSocketFile(). ' fail case '.$socketServer->errMsg);
}
while (1){
$client = $socketServer->accept(-1);
if(!$client){
return;
}
if($this->getConfig()->isAsyncCallback()){
Coroutine::create(function ()use($client){
try{
$this->onAccept($client);
}catch (\Throwable $throwable){
$this->onException($throwable,$client);
}
});
}else{
try{
$this->onAccept($client);
}catch (\Throwable $throwable){
$this->onException($throwable,$client);
}
}
}
}
看错了
smarty模板为了协程安全,引用了外部的进程来渲染,但是发现外部进程里面的socket也有使用协程呀,那不是也有协程安全问题吗 vendor/easyswoole/component/src/Process/Socket/AbstractUnixProcess.php
接收到一个客户端的$client,直接抛给协程,如果并发接收$client, 协程就不安全了