php if else repeat

Posted on 2005-04-29
Last Modified: 2006-11-18
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?
Question by:pugandjody
    LVL 4

    Accepted Solution


    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 ...

    LVL 14

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now