php if else repeat

Here is the script I have:

$file = file_get_contents('');
$parts = preg_split("/[\s]+/",$file);
$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);

   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?
Who is Participating?
VIkasumitConnect With a Mentor Commented:

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

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

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.

EE Cleanup Volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.