Web Analytics Made Easy -
StatCounter Socket Timeout - CodingForum

Announcement

Collapse
No announcement yet.

Socket Timeout

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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)

    Comment


    • #3
      set_time_limt(int)

      where int is the number in seconds

      Comment


      • #4
        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.

        Comment


        • #5
          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!

          Comment


          • #6
            Yes, I forgot to add that '0' represents that the script will run continuously.

            Comment


            • #7
              Thats the problem set_time_limit() doesnt work. I've already tried it

              Comment


              • #8
                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)

                Comment


                • #9
                  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

                  Comment


                  • #10
                    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; May 8, 2012, 04:13 PM.

                    Comment

                    Working...
                    X