function post($url, $data = '', $head = 'application/x-www-form-urlencoded') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type:{$head};charset=utf-8;")); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); if (!empty($data)) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } $output = curl_exec($ch); curl_close($ch); return $output; } $url = 'http://localhost/test.php'; $res = []; //模拟100条数据 for ($i=0; $i < 100; $i++) { $res[$key] = post($url, 'key='.$i); } var_dump($res);
請教大佬如何改成curl_multi_init多執行緒的呢?我的思路是把$data數組拆分array_chunk($data, 15, true);然後再進行CURL,但我是新手,沒有看懂網上的例子,請求幫助