I am trying to bombard my site using simultaneous 50-100+ curl connections
.
i have made list of URLs in array [post IDs are incremental], so no same url will be accessed twice as there is caching enabled on server.
I want to do this purely in php-curl
as i am familiar with php.
i have looked on stackoverflow and found this PHP: Opening URLs concurrently to simulate a DOS attack?
but there is no curl solution to do what i am trying to do. i don't want to use 3rd party tools. as some are for windows , some are for linux, some are outdated while i am more familiar with php.
Right now my code waits for current connections to close and then start new ones. while i don't want to wait for open connections to close and just keep on starting new connections.
here is my code so far.
<?php
$my_site_url = 'https://example.com/item/post_id';
$threads = 80;
$all_post_ids = array();
//get all ids in the array
for($int = 50; $int <= 200000 ; $int++){
$all_post_ids[] = $int;
}
//printr($all_post_ids);
//make chunks from the big array
foreach(array_chunk($all_post_ids, $threads) as $post_ids_chunk) {
$ch = curl_multi_init();
foreach ($post_ids_chunk as $i => $each_id) {
$url = str_replace("post_id" , $each_id , $my_site_url) ;
echo $url."\n" ;
$conn[$i] = curl_init($url);
curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($conn[$i], CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($conn[$i], CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($conn[$i], CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36');
curl_setopt($conn[$i], CURLOPT_HEADER, 0);
curl_multi_add_handle($ch, $conn[$i]);
}
do {
$status = curl_multi_exec($ch, $active);
} while ($status === CURLM_CALL_MULTI_PERFORM || $active);
foreach ($post_ids_chunk as $i => $each_id){
//$header[$i] = curl_getinfo($conn[$i]);
//var_dump( $header[$i]);
//echo $header[$i]['http_code'];
//$received_data[$i] = curl_multi_getcontent($conn[$i]);
curl_multi_remove_handle($ch, $conn[$i]);
}
curl_multi_close($ch);
}
So how can i not wait open connections to close and start new ones lets say per second or as soon as possible.
What i am missing here ?
Thanks for your time.