Friday 15 February 2013

retry a statement inside an array loop in php but with the next value of the array -


I'm here again, learning more about PHP, but there are still some problems for my scenario , Most of my scenario has been programmed and resolved without problem, but I got a problem, but to understand it, I have to explain it first:

I have a PHP script Can be brought by any client and its work is a Proxy Prap To do this, ping the proxy to a list, which defines manually, to know if a proxy is available, if it is available, then I use "curl" with a post method to add a Moves forward to get feedback. Logic goes like this:

  $ proxyList = array ( '192.168.3.41:8013' = & gt; 0, '192.168.3.41:8023'=>0,' 192.168.3.41: 8033 '=> 0); $ ErrorCounter = 0; foreach ($ proxyList as $ key = & gt; $ value) {(isUrlAvailable ($ key) {// This means that if it is not available I errors $ errorCounter ++ count!} else {// This means $ results = callThisProxy ($ key);}}   

function "isUrlAvailable" a $ Fsockopen If If the proxy is available No, I use make. post with curl as explained earlier, the function is something like callThisProxy () :

  $ Ch = curl_init ($ proxyUrl); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, 'xmlQuery =' $ rawXml.); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); $ info = curl_exec ($ ch), if ($ isDebug) information {echo 'moment' .. $ information '& lt; br / & gt;';} curl_close ($ ch);   

But, what are we going to do? Some scenarios, what if I close the proxy between verification and call proxies test again I mean:

  foreach ($ proxyList as $ Key = & gt; $ Value) is available {If (URL ($ key) {// This I Ans it would mistake I errors is not available errorCounter ++;} Else {// This means that it is available $ result = callThisProxy ($ Key); // If the result is being processed, then what will happen to kill the proxy?}}   

I tested it and when I do this, $ The result comes in the form of an empty string '' . But the problem is that I have lost that request, And my goal is to try it again with the next $ which is a proxy, I was thinking about a "do, while" when I called the result But not sure if this is okay or there is a better way of doing this, please ask for help with this issue. Thank you in advance for your time. Any answer is welcome Thanks.

Maybe something like this:

  $ result = ""; while ($ result == " ) { Foreach ($ proxyList $ key = & gt; $ value) {ifUrl Available ($ key)) {$ errorCounter ++; } And {$ result = call it proxy ($ key); }}} // Now check the $ result, the first successful call should be thisProxy () // result, or no keys work    

No comments:

Post a Comment