Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: Socket Timeout

  1. #1
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Socket Timeout

    How can I set a socket timeout for connecting. I want it so that if it doesn't connect within 1 second then it will timeout. I'm not using fsockopen(like it owuld matter, the timeout is messed on that). I've tried using various ways of implementing a timeout but none have worked :\. Any ideas?

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    please explain whats wrong with the timeout parameter for fsockopen() ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Registered User
    Join Date
    Jan 2004
    Location
    Florida
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    set_time_limt(int)

    where int is the number in seconds

  • #4
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    set_time_limit() will stop the script. I just want it to stop trying to connect and continue with the rest of the script.

    To answer your question I am making a simple tool that will check to see if the ports on a users computer are open, closed, or invisible(thats why im using socket functions rather then just fsockopen() ). If the users ports are in stealth it takes a REALLY long time to timeout.

  • #5
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    set_time_limit
    (0);
    /* Connect to Socket, etc., etc. */
    ?>
    will not stop the script. It will continue on and on until the script is manually stopped.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #6
    Registered User
    Join Date
    Jan 2004
    Location
    Florida
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I forgot to add that '0' represents that the script will run continuously.

  • #7
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats the problem set_time_limit() doesnt work. I've already tried it

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    Hidden ports are only hidden to non trusted hosts , so unless your IP is in the trusted list then port should simply not show up ... I appreciate that is not happening for you but since firewall implementations differ I dont know what to say .

    If you are doing a lot of scanning (and I assume with permission) perhaps look at the newer http://www.php.net/stream_set_blocking () which will if nothing else allow your application to continue while you wait for the timeout.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by john2496 View Post
    How can I set a socket timeout for connecting. I want it so that if it doesn't connect within 1 second then it will timeout. I'm not using fsockopen(like it owuld matter, the timeout is messed on that). I've tried using various ways of implementing a timeout but none have worked :\. Any ideas?
    Hey john! I've been doing a bit of research into your question and found a few potential solutions. As you already know, socket_set_timeout, doesn't work, ever. In place of this function you should use socket_select in a loop to detect the socket status, after every iteration sleep for 500ms. I don't have any example code to post but check http://us.php.net/manual/en/function...et-timeout.php. You'll be able to find working code examples there! Good luck!

    ~john2496

  • #10
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by john2496 View Post
    Hey john! I've been doing a bit of research into your question and found a few potential solutions. As you already know, socket_set_timeout, doesn't work, ever. In place of this function you should use socket_select in a loop to detect the socket status, after every iteration sleep for 500ms. I don't have any example code to post but check http://us.php.net/manual/en/function...et-timeout.php. You'll be able to find working code examples there! Good luck!

    ~john2496
    It might be better to use cURL instead of PHP's socket functions. Try using cURL to 'ping' the client before attempting to open a socket. Use the timeout options below...

    PHP Code:
    curl_setopt($chCURLOPT_TIMEOUT2);
    curl_setopt($chCURLOPT_CONNECTTIMEOUT2); 
    Also, the set_socket_timeout / set_time_limit bug was resolved years ago - OP should migrate to php 5. Good luck!
    Last edited by john2496; 05-08-2012 at 09:13 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •