简体   繁体   中英

Foreach Loop only loops once

I am trying to make many requests to my website, using proxies and headers in PHP, and grab a proxy line by line from a text file to use in the file_get_contents, however I have 3 proxies in the text file (one per line) and the script is only using one, then ending. (I am executing it from command line)

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

Right now its only using the first proxy and it is returning the value correctly, however then the script stops. My goal is for it to endlessly make requests until it runs out of proxies in proxies.txt

这应该适合你:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM