开发者

Data Change on CURL Respond PHP

开发者 https://www.devze.com 2023-04-03 16:00 出处:网络
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 c

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;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号