diff --git a/src/Cron/CronManager.php b/src/Cron/CronManager.php index bb8deef..534d5ed 100644 --- a/src/Cron/CronManager.php +++ b/src/Cron/CronManager.php @@ -206,7 +206,7 @@ public function getTaskCallable(string $cronId, string $class, ?string &$cronTyp $task = function (string $id, $data) use ($class) { ProcessManager::run('CronWorkerProcess', [ 'id' => $id, - 'data' => json_encode($data), + 'data' => json_encode($data, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE), 'class' => $class, 'cron-sock' => $this->getSocketFile(), ], null, null, $this->stdOutput); @@ -234,7 +234,7 @@ public function getTaskCallable(string $cronId, string $class, ?string &$cronTyp $task = function (string $id, $data) use ($process) { ProcessManager::run($process->name, [ 'id' => $id, - 'data' => json_encode($data), + 'data' => json_encode($data, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE), 'cron-sock' => $this->getSocketFile(), ], null, null, $this->stdOutput); }; diff --git a/src/Cron/Scheduler.php b/src/Cron/Scheduler.php index 028dcad..291a203 100644 --- a/src/Cron/Scheduler.php +++ b/src/Cron/Scheduler.php @@ -103,7 +103,7 @@ public function run(ITaskParam $param) 'data' => $task->getData(), 'task' => \is_callable($taskClass) ? null : $taskClass, 'type' => $type, - ]), mt_rand(0, $swooleServer->setting['worker_num'] - 1)); + ], \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE), mt_rand(0, $swooleServer->setting['worker_num'] - 1)); break; case CronTaskType::ALL_WORKER: /** @var ISwooleServer $server */ @@ -116,7 +116,7 @@ public function run(ITaskParam $param) 'data' => $task->getData(), 'task' => \is_callable($taskClass) ? null : $taskClass, 'type' => $type, - ]); + ], \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); for ($i = 0; $i < $swooleServer->setting['worker_num']; ++$i) { $swooleServer->sendMessage($message, $i); diff --git a/src/Process/Pool.php b/src/Process/Pool.php index 867f40a..2f46da8 100644 --- a/src/Process/Pool.php +++ b/src/Process/Pool.php @@ -230,13 +230,7 @@ private function startWorker($workerId) return; } - $data = json_decode($content, true); - if (false === $data) - { - Log::warning('%s: Decode pipe message content failed'); - - return; - } + $data = json_decode($content, true, 512, \JSON_THROW_ON_ERROR); $this->trigger('Message', [ 'pool' => $this, 'worker' => $worker, diff --git a/src/Process/Process.php b/src/Process/Process.php index 734496e..614c49d 100644 --- a/src/Process/Process.php +++ b/src/Process/Process.php @@ -14,7 +14,7 @@ class Process extends \Swoole\Process public function sendMessage(string $action, array $data = []) { $data['a'] = $action; - $message = json_encode($data); + $message = json_encode($data, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); return $this->write($message); } diff --git a/src/Server/Util/AmqpServerUtil.php b/src/Server/Util/AmqpServerUtil.php index 74a0925..545af89 100644 --- a/src/Server/Util/AmqpServerUtil.php +++ b/src/Server/Util/AmqpServerUtil.php @@ -78,7 +78,7 @@ public function sendAmqpMessage(string $action, array $data = [], string $routin { $data['action'] = $action; $data['workerId'] = Worker::getWorkerId(); - $message = json_encode($data); + $message = json_encode($data, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); $amqpMessage = new Message(); $amqpMessage->setBody($message); $amqpMessage->setRoutingKey($routingKey); diff --git a/src/Server/Util/LocalServerUtil.php b/src/Server/Util/LocalServerUtil.php index e17ea50..c5b07d2 100644 --- a/src/Server/Util/LocalServerUtil.php +++ b/src/Server/Util/LocalServerUtil.php @@ -37,7 +37,7 @@ class LocalServerUtil implements ISwooleServerUtil public function sendMessage(string $action, array $data = [], $workerId = null): int { $data['action'] = $action; - $message = json_encode($data); + $message = json_encode($data, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); return $this->sendMessageRaw($message, $workerId); } diff --git a/src/Server/Util/RedisServerUtil.php b/src/Server/Util/RedisServerUtil.php index d558499..17bee05 100644 --- a/src/Server/Util/RedisServerUtil.php +++ b/src/Server/Util/RedisServerUtil.php @@ -50,7 +50,7 @@ public function sendMessage(string $action, array $data = [], $workerId = null): { $data['action'] = $action; $data['workerId'] = Worker::getWorkerId(); - $message = json_encode($data); + $message = json_encode($data, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); return $this->sendMessageRaw($message, $workerId); }