2011-09-06 74 views
0

只有一个问题。我得到一个基于cURL的代码,它发送一个请求到serwer,然后如果响应是'有效的'它是在做一个sql查询,但是如果响应'忙',我需要更改脚本正在使用的代理。CURL响应的数据更改PHP

我做这样说:

$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]; 

,但它不工作。

有什么建议吗?

问候。

+0

既然你已经有一个'for',在'$代理= $ proxys [$ N + 1]循环他们。 '应该是多余的 - 你应该写下来,以便你可以['继续;](http://php.net/manual/en/control-structures.continue.php)代替... – DaveRandom

回答

1

对于初学者,file('http_proxy.txt');将在您的文件中保留换行符,因此使用FILE_IGNORE_NEW_LINES标志省略此项。然后,你可以使用break;成功地使用上的代理卷曲后停止循环:

$proxys = file('http_proxy.txt', FILE_IGNORE_NEW_LINES); 
foreach($proxys as $proxy) 
{ 
    $response = sendRequestTo($proxy); 
    if($response == 'valid') 
    { 
     performQuery($proxy); 
     break; 
    } 
}