Foreach outline only loop once

I am trying to make many requests on my website using proxies and headers in PHP, and grab the proxy line by line from a text file for use in file_get_contents, however I have 3 proxies in a text file (one per line), and the script uses only one and then ends. (I execute it from the 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; } ?> 

Now it uses only the first proxy server and returns the value correctly, but then the script stops. My goal is for him to make endless requests until the proxies in proxies.txt end

+5
source share
1 answer

This should work for you:

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

Source: https://habr.com/ru/post/1210865/


All Articles