I have the following function:
function pegarWS($numero){
$PEGAR_WS = 'http://ws.com.br';
$URL = $PEGAR_WS.$numero;
$arrayReturn = json_decode( @file_get_contents($URL), true );
I wanted to access the URL through multiple proxy
I found something like:
$proxies = array( '192.168.0.2:3128', '192.168.8.2:3128', '192.168.10.2:80' );
// Pick a random proxy:
$proxy_to_use = $proxies[ rand( 0, count( $proxies ) -1) ];
$aContext = array(
'http' => array(
'proxy' => 'tcp://' . $proxy_to_use,
'request_fulluri' => true,
),
);
I was able to solve the problem with Guilherme's answer.
The following code was used:
function pegarWS($numero){
$PEGAR_WS = 'http://ws.com.br';
$URL = $PEGAR_WS.$numero;
$proxies = file('pasta/secreta/inacessivel/via/http/proxies.txt');
//Limpa espaços em branco
$proxies = array_map(function ($proxy) {
return trim($proxy);
}, $proxies);
// pegar random proxy
$proxy_to_use = $proxies[ rand( 0, count( $proxies ) -1 ];
$aContext = array(
'http' => array(
'proxy' => $proxy_to_use,
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($aContext);
$arrayReturn = json_decode( @file_get_contents($URL, false, $cxContext), true);
With option to search in a .txt.
Now I'm stopped at another point.
$proxy_to_use = $proxies[ rand( 0, count( $proxies ) -1) ];
Is it possible for it to read the txt file from first to last and then do the process again? without being random?