PHP curl_multi_exec不同时启动多个线程

PHP curl_multi_exec不同时启动多个线程,php,curl,Php,Curl,使用PHP curl_multi_init代码 <?php // create both cURL resources $ch1 = curl_init(); $ch2 = curl_init(); // set URL and other appropriate options curl_setopt($ch1, CURLOPT_URL, "http://example.com/test-3.php"); curl_setopt($ch1, CURLOPT_HEAD

使用PHP curl_multi_init代码

<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://example.com/test-3.php");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://example.com/test-3.php");
curl_setopt($ch2, CURLOPT_HEADER, 0);

//create the multiple cURL handle
$mh = curl_multi_init();

//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

//execute the multi handle
do {
    $status = curl_multi_exec($mh, $active);
    if ($active) {
        curl_multi_select($mh);
    }
} while ($active && $status == CURLM_OK);

//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);

?>
当我运行PHP Multi-INIT时,我需要10秒来完成进程(5+5睡眠秒),通常需要在5秒内完成,而不是在10秒内完成,因为应该同时启动所有2个进程

第一次玩这个代码,所以我不确定我在测试中做错了什么


如何使流程同时启动?

我会使用forks,但这是我做这类事情的方式:)你能给我举一个使用forks和cURL的例子吗?谢谢选中此项:,你可以在子进程中放入任何你想要的内容,在代码中注释为
//child
我会使用forks,但这是我做这类事情的方式:)你能给我举一个使用forks和cURL的例子吗?谢谢选中此项:,您可以在子进程中放入任何需要的内容,在代码中注释为
//child
sleep(5);
echo time();