Foreach 循环只循环一次


Foreach Loop only loops once

我正在尝试使用PHP中的代理和标头向我的网站发出许多请求,并从文本文件中逐行获取代理以在file_get_contents中使用,但是我在文本文件中有3个代理(每行一个),脚本只使用一个,然后结束。(我正在从命令行执行它)

<?php
$proxies = explode("'r'n", file_get_contents("proxies.txt"));
foreach($proxies as $cpr0xy) {
$aContext = array(
    'http' => array(
        'proxy' => "tcp://$cpr0xy",
        'request_fulluri' => true,
        'method'=>"GET",
        'header'=>"Accept-language: en'r'n" .
         "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'r'n" 
    ), );
$rqcon = stream_context_create($aContext);
$destc = file_get_contents("http://domain.com/file.php", False, $rqcon);
echo $destc;
 } ?>

现在它只使用第一个代理,并且它正确地返回了值,但是脚本停止了。我的目标是让它无休止地发出请求,直到代理中的代理用完.txt

这应该适合您:

$proxies = explode(PHP_EOL, file_get_contents("proxies.txt"));