1
I have the following function:
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 ];
foo
In particular: (I need to adapt)
$proxy_to_use = $proxies[ rand( 0, count( $proxies ) -1 ];
Instead of searching for the proxy form Random (see code), I need to change it so that it reads line by line from txt (one at a time) in loop. That is, read the first line, then the second and so on.. When you get to the last line it goes back to the first line.
It is not clear what you need or what error you are getting
– Jorge Costa
@Jorgecosta, I left the most detailed question.
– J. Doe
Why not put the code inside the map array ?
– Jorge Costa
@Jorgecosta, I stopped where the question is :-( I can’t read line by line.
– J. Doe
To see if I realized every time I invoke pegWS you want to return a line from the file sequentially
– Jorge Costa
@Jorgecosta.
– J. Doe
Then you will have to keep an index of the last line used and maybe also the array of lines to not always read the file (best performance)
– Jorge Costa
But do you want to recover those lines within the file? Or every time you call the function it returns a specific line?
– Andrei Coelho
@Andreicoelho, each time he opens the file, he returns the next line and when he reaches the last line, he goes back to the first.
– J. Doe
I had asked the wrong question. What I wanted to know is if you want to recover these lines within the function or if each time you call the function it returns the line... But I believe it’s the second option.
– Andrei Coelho
Was that it? Retrieve line by line every function call?
– Andrei Coelho
That’s exactly it. I’m just not getting it into my code...
– J. Doe
There’s another option. I’ll post it to you.
– Andrei Coelho
Try the option using session.
– Andrei Coelho