1
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 various 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.
That’s what the code looks like:
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 standing in another spot.
$proxy_to_use = $proxies[ rand( 0, count( $proxies ) -1) ];
Is it possible for him to read the txt file from first to last and then do the process again? without being in a form?
Saved @Guilherme~ ! Another question, is it possible to call in a.txt file with the proxy? What would it look like?
– Marcelo
@Marcelo . txt local on the same server? Calling would be the same as reading the file?
– Guilherme Nascimento
yes. The file would be on the server and not to list all proxy numbers in the code I wanted to read them by a txt (for easy editing)
– Marcelo
@Marcelo ah entendi, you want to leave the proxy Ips in a . txt, I will put an example in the answer
– Guilherme Nascimento
@Marcelo edited the answer, see if this is what you want
– Guilherme Nascimento
it worked. Thank you very much! I edited the question with a remark if I can help. Thank you!
– Marcelo