How do you create a php script that executes or visits a set of dynamic urls such as http://www.mysite.com/blah&u=y http://www.mysite.com/blah&u=y+1 http://www.mysite.com/blah&u=y+2 http://www.mysite.com/blah&u=y+3 . . . http://www.mysite.com/blah&u=x a range y though x? and with a delay of n seconds between urls? thanks
I tried this: <?php $time=1; $y=0; $x=10; for ($i=$y;$i<=$x;$i++) { $ch = curl_init(); $url = "http://www.mysite.com/blah?u=".$i; curl_setopt($ch, CURLOPT_URL, $url); curl_exec($ch); curl_close($ch); sleep($time); } ?> but getting a 500 Servlet Exception error
lol You have an infinite loop... for the for loop: i is equal to y. as long as i is less than or equal to x: process the loop. note how you reset i to the value of y (0) everytime the loop is itterated. in fact it doesn't need to be that complicated at all: for ($i = 1; $i <= 10; $i++) { $ch = curl_init(); $url = "http://www.mysite.com/blah?u=".$i; curl_setopt($ch, CURLOPT_URL, $url); curl_exec($ch); curl_close($ch); sleep(1); } will do : http://www.mysite.com/blah?u=1 ... http://www.mysite.com/blah?u=10
peoplesmind has indeed suggested the best method and CURL should be the best option across different environments. This only thing I would say is if you are doing loads of URL's at once you might want to explore the multi execute function CURL provides which would allow many to run at the same time, dramaticlly reducing the runtime of the script.