#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    9
    Rep Power
    0

    Need help skipping unresponsive servers


    Hi there,

    I created a script that Gets A Servers Information from a List of IP's it works and sends the information to the PHP page, The only problem is that when It runs into an IP that doesn't respond it stops the php page,

    Can anyone help me Skip to the next line in the txt instead of waiting for an unresponsive server

    Heres a link to the .txt: http:// master.sa-mp .com /0.2.2/servers

    here is a link to the script: pastebin .com /m2e21be72
  2. #2
  3. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    113
    It depends on how you are connecting to those servers (i.e. over what protocol). If you are expecting to find a web service running on those ports, then you should use curl and apply the CURLOPT_CONNECTTIMEOUT to configure appropriate timeouts. If it's not http you're talking, then more info would be required.

    christo

    Comments on this post

    • ManiacDan agrees : that's what I would do
    This is me: http://chris.uk.com
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    358
    Rep Power
    163
    Try simply looking for the url or file first and using fsockopen with a timeout... although most of this script is way beyond what you need...you get the drift.

    From the file_exists php manual.

    Basically you are checking if it is 'there' before dealing with it.


    Code:
    <?php 
    function rtsp_exists($url) {
    
        $server = parse_url($url, PHP_URL_HOST);
    
        //Open connection (15s timeout)
        $sh = fsockopen($server, $port, $err, $err_otp, 15);
        //Check connections
        if(!$sh) return false;
        //Close socket
        fclose($sh);
    }
    I cut out some code, but you get the drift. Also something like it is available with cURL.

    I for one just think a simple !file_exists with a timer works rather easy...a 2 second timer probably be fine...

    If file exists, means you can access it...means you can do what you want.


    more here

    Php manual file exists



    resource fsockopen ( string $hostname [, int $port [, int &$errno [, string &$errstr [, float $timeout ]]]] )
    http://us.php.net/fsockopen



  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    9
    Rep Power
    0
    Hmm i wish i new as much knowledge in this kind of php as you do


    Can you modify the code and maybe post the new version here

IMN logo majestic logo threadwatch logo seochat tools logo