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,但我是新手,没有看懂网上的例子,请求帮助
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号