php swoole 队列、异步、协程并发curl请求

 public function curls()
    {
        cli_set_process_title(__FILE__ . ':curls');
        $file_mtime = $this->file_mtime();
        $st = time();

        error_reporting(E_ALL);
        ini_set('swoole.display_errors', 'On');

        \Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);
        \Swoole\Coroutine\run(function () use ($st, $file_mtime) {
            for ($i = 0; $i < 5; $i++) {
                \Swoole\Coroutine::create(function () use ($i, $st, $file_mtime) {
                    $redis = new Redis();
                    $redis->connect('10.29.185.7', 6383);
                    while (true) {
                        $task = $redis->blPop('curl_queue', 5);
                        if (!empty($task)) {
                            [$key, $val] = $task;
                            $json = json_decode($val, true);
                            if ($json) {
                                $method = $json['method'];
                                $uri = $json['uri'];
                                $headers = $json['headers'] ?? [];
                                $body = $json['body'] ?? null;

                                $ch = curl_init();
                                if ($method === 'POST') {
                                    curl_setopt($ch, CURLOPT_POST, true);
                                    curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
                                }
                                if (count($headers)) {
                                    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                                }
                                curl_setopt($ch, CURLOPT_URL, $uri);
                                curl_setopt($ch, CURLOPT_HEADER, false);
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                $result = curl_exec($ch);
                                curl_close($ch);
                            }
                        }
                        if ($file_mtime != $this->file_mtime()) break;
                        if (time() - $st > 3600) break;
                    }
                });
            }
        });
    }