Curl_multi_init single thread to multi-thread problem
Bob pang
Bob pang 2022-06-06 08:45:42
0
0
1023
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);

Could you please tell me how to change curl_multi_init to multi-threading? My idea is to split the $data array into array_chunk($data, 15, true); and then perform CURL, but I am a newbie and have not understood the online examples. Please help.

Bob pang
Bob pang

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template