tags:

views:

43

answers:

1

hi, i want my curl to use random proxy from the proxy.txt file that is saved in my site with this format:

1.1.1.1:8080
2.2.2.2:8080
3.3.3.3:8080
...

I want it to make it randomly so that every time it uses different proxy from the proxy.txt list, but i have no idea i can code something like that in php.

+1  A: 

Read a random line from a file:

srand ((double)microtime()*1000000);
$f_contents = file ("proxy.txt");
$line = $f_contents[array_rand ($f_contents)];
print $line;

All you need now is:

function get_random_proxy()
{
    srand ((double)microtime()*1000000);
    $f_contents = file ("proxy.txt");
    $line = $f_contents[array_rand ($f_contents)];
    return $line;
}
Am