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

    Join Date
    Sep 2013
    Posts
    28
    Rep Power
    0

    Fsockopen catch error


    Morning. Im trying to check if i can connect via telnet and echo a string depending on the result. The problem is it shows the error message followed by echoes

    PHP Code:
        $usenet fsockopen($cfgServer$cfgPort$errno$errstr$cfgTimeOut);      
    if(!
    $usenet){     echo "failed";     echo "  ".date('H:i:s'time()+3600);}     
    else { echo 
    "connected"; } 
    result

    Warning: fsockopen(): unable to connect to 213.***.***.***:**** (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\projects\Testing2.0\privatepingtelnet.php on line 17 failed 09:27:27
    expected result

    failed 09:27:27
    How to properly catch the error ?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    28
    Rep Power
    0
    Never mind

    PHP Code:
    @fsockopen 
  4. #3
  5. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,119
    Rep Power
    9398
    Yeah. You can't really "catch" warnings like that, but since you're explicitly testing for success and failure, and are well aware that the connection may time out (or have other kinds of problems), using @ to suppress the error is alright.

IMN logo majestic logo threadwatch logo seochat tools logo