function stream_onRead($fp) { echo fread($fp, 1024) . "\n"; sleep(1); swoole_event_write($fp, "hello world"); //swoole_event_set($fp, null, null, SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE); //swoole_event_del($fp); //fclose($fp); }
protected function startCommandHandler() { $sockFile = $this->runDir . "command-{$this->swoolePort}.sock"; file_exists($sockFile) and unlink($sockFile); ini_set('html_errors', 0); if (!($this->commandServer = stream_socket_server('unix://' . $sockFile, $errNo, $errStr))) { // @codeCoverageIgnoreStart $this->cliOutput('error', "Command handler start failed: {$errStr} ({$errNo})"); } else { swoole_event_add($this->commandServer, function () { $conn = stream_socket_accept($this->commandServer, 0); swoole_event_add($conn, function ($conn) { $command = fread($conn, 128); $result = $this->processCommand($command); swoole_event_write($conn, $result); swoole_event_del($conn); }); }); $this->cliOutput('info', 'Command handler started.'); } }