• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

php if else repeat

Here is the script I have:

<?php
$file = file_get_contents('http://loot.alumnigroup.org/?hostfile=1');
$parts = preg_split("/[\s]+/",$file);
shuffle($parts);
$parts = explode(':',$parts[0]);

$fp = fsockopen("$parts[0]", $parts[1]);
if (!$fp) {
   echo "Unable to open\n";
} else {

   fwrite($fp, "GNUTELLA CONNECT/0.6\r\nUser-Agent: LimeWire/4.2.6 (Pro)\r\nX-Ultrapeer-Query-Routing: 0.1\r\nPong-Caching: 0.1\r\nX-Ultrapeer: False\r\n\r\n");
   stream_set_timeout($fp, 3000);
   $res = fread($fp, 2000);

   $info = stream_get_meta_data($fp);
   fclose($fp);

   if ($info['timed_out']) {
       echo 'Connection timed out!';
   } else {
       echo "Connected to...<BR><BR>\n{$parts[0]}:{$parts[1]}<BR><BR>\nserver response...<BR><BR>\n";
       echo $res;
   }

}
?>

What it does is it retrieves and ip address and port to connect to, sends a string and then recieves it.
What I would like it to do is if it gets a time out, is unable to open, or the server responds back with anything except "GNUTELLA/0.6 200 OK", I want it to start over again...
So if it returns "GNUTELLA/0.6 200 OK" then it stops, but if anything else happens then start over...

any ideas?
Thanks!
0
pugandjody
Asked:
pugandjody
1 Solution
 
VIkasumitCommented:
Hi,

Simple put your code in the Do While
do{
...
...
...
}while(reponse<>"GNUTELLA/0.6 200 OK")

And I will repeat your code till it get the response ...

VIkasumit
0
 
hujiCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: VIkasumit

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Huji
EE Cleanup Volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now