Multithreading - curl_multi_init concurrency testing issue with PHP
世界只因有你
世界只因有你 2017-06-13 09:21:51
0
2
783
    $query_arr = array();
    for ($k = 0;$k<5;$k++){//请问5代表的是什么?
        $query_arr[] = 'http://www.segmentfault.com/json';
    }
    for ($i = 0;$i<70;$i++){//请问70代表的是什么?
        $ch = curl_multi_init();
        $count = count($query_arr);
        $ch_arr = array();
        for ($j = 0; $j < $count; $j++) {
            $query_string = $query_arr[$j];
            $ch_arr[$j] = curl_init($query_string);
            curl_setopt($ch_arr[$j], CURLOPT_RETURNTRANSFER, true);
            curl_multi_add_handle($ch, $ch_arr[$j]);
        }
        $running = null;
        do {
            curl_multi_exec($ch, $running);
        } while ($running > 0);
        for ($l = 0; $l < $count; $l++) {
            $results[$l] = curl_multi_getcontent($ch_arr[$l]);
            curl_multi_remove_handle($ch, $ch_arr[$l]);
        }
        curl_multi_close($ch);
    }

What do the 5 and 70 in the code represent?

世界只因有你
世界只因有你

reply all(2)
阿神

Five URLs were created (ps: these 5 URLs are the same) and executed 70 times in total, which means a total of 350 requests can be understood as 5 concurrent executions 350 times
Similar to ab's ab -c 5 -n 350 http ://www.segmentfault.com/json

However, curl_multi_init is a method of IO multiplexing. There is a certain difference between it and the real stress test interface. You can try ab siege
or use pthreads to execute scripts for concurrent testing

黄舟

That’s 5 concurrencies, looping 70 times. . . Nothing special

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template