Just one question. I got an cURL based code, and it send a request to the serwer, then if the respond is 'valid' it's making a sql query, but if the res开发者_开发知识库pond is 'busy' I need to change the proxy which the script is using.
I'm making it this way:
$proxys = file('http_proxy.txt');
...then...
for($n = 0, $count = count($proxys); $n <= $count; $n++) {
...and to change the proxy I used something like this:
$proxy = $proxys[$n + 1];
but it doesn't work.
Any suggestions?
Regards.
For starters, file('http_proxy.txt');
will retain the newlines in your file, so use the FILE_IGNORE_NEW_LINES
flag to omit this. Then, you could use break;
to stop the loop after succesfully using CURL on a proxy:
$proxys = file('http_proxy.txt', FILE_IGNORE_NEW_LINES);
foreach($proxys as $proxy)
{
$response = sendRequestTo($proxy);
if($response == 'valid')
{
performQuery($proxy);
break;
}
}
精彩评论