Long sleep() and time-out's

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vincent Delporte

    #1

    Long sleep() and time-out's

    Hi

    The script I'm writing needs to wait a random amount of time (1-300s)
    between each iteration of a loop, eg.

    while(condition ) {
    do something
    //wait between 1s and 5 minutes
    sleep(rand(1,30 0));
    }

    Problem is, a browser times out if it doesn't get an answer within
    about 30 seconds. Is the idea of having a PHP script sleep for a
    longer amount of time incompatible with web applications? Any
    work-around?

    Thank you.
  • Rik

    #2
    Re: Long sleep() and time-out's

    Vincent Delporte wrote:[color=blue]
    > Hi
    >
    > The script I'm writing needs to wait a random amount of time (1-300s)
    > between each iteration of a loop, eg.
    >
    > while(condition ) {
    > do something
    > //wait between 1s and 5 minutes
    > sleep(rand(1,30 0));
    > }
    >
    > Problem is, a browser times out if it doesn't get an answer within
    > about 30 seconds. Is the idea of having a PHP script sleep for a
    > longer amount of time incompatible with web applications? Any
    > work-around?[/color]

    Feed some bogus information?

    for($i=0;$i<=ra nd(1,60);$i++){
    echo ' ';
    sleep(5);
    }

    Not very elegant, but gets the job done I think.

    Grtz,
    --
    Rik Wasmus


    Comment

    • Kim André Akerø

      #3
      Re: Long sleep() and time-out's

      Vincent Delporte wrote:
      [color=blue]
      > Hi
      >
      > The script I'm writing needs to wait a random amount of time (1-300s)
      > between each iteration of a loop, eg.
      >
      > while(condition ) {
      > do something
      > //wait between 1s and 5 minutes
      > sleep(rand(1,30 0));
      > }
      >
      > Problem is, a browser times out if it doesn't get an answer within
      > about 30 seconds. Is the idea of having a PHP script sleep for a
      > longer amount of time incompatible with web applications? Any
      > work-around?[/color]

      Use set_time_limit:


      From the manual:[color=blue]
      > Set the number of seconds a script is allowed to run. If this is
      > reached, the script returns a fatal error. The default limit is 30
      > seconds or, if it exists, the max_execution_t ime value defined in the
      > php.ini. If seconds is set to zero, no time limit is imposed.
      >
      > When called, set_time_limit( ) restarts the timeout counter from zero.
      > In other words, if the timeout is the default 30 seconds, and 25
      > seconds into script execution a call such as set_time_limit( 20) is
      > made, the script will run for a total of 45 seconds before timing out.[/color]

      Especially that last part should be useful to you.

      --
      Kim André Akerø
      - kimandre@NOSPAM betadome.com
      (remove NOSPAM to contact me directly)

      Comment

      • Rik

        #4
        Re: Long sleep() and time-out's

        > Vincent Delporte wrote:[color=blue][color=green]
        >> Problem is, a browser times out if it doesn't get an answer within[/color][/color]
        -----------------^^^^^^

        Kim André Akerø wrote:[color=blue]
        > Use set_time_limit:
        > http://php.net/set_time_limit[/color]

        Nope, except if the OP has got his question wrong.
        Browser time-outs are beyond settings you can control, you can only
        urge/fool them.

        Grtz
        --
        Rik Wasmus


        Comment

        • Vincent Delporte

          #5
          Re: Long sleep() and time-out's

          On Wed, 14 Jun 2006 18:19:45 +0200, "Rik" <luiheidsgoeroe @hotmail.com>
          wrote:[color=blue]
          >for($i=0;$i<=r and(1,60);$i++) {
          > echo ' ';
          > sleep(5);
          >}
          >
          >Not very elegant, but gets the job done I think.[/color]

          Thx but it doesn't work: I don't see how I can have the script pause
          for 1-300 seconds, while still send some empty string to the browser
          every 5 seconds just to avoid a time-out error. Did I get this wrong?

          Comment

          • Rik

            #6
            Re: Long sleep() and time-out's

            Vincent Delporte wrote:[color=blue]
            > On Wed, 14 Jun 2006 18:19:45 +0200, "Rik" <luiheidsgoeroe @hotmail.com>
            > wrote:[color=green]
            >> for($i=0;$i<=ra nd(1,60);$i++){
            >> echo ' ';
            >> sleep(5);
            >> }
            >>
            >> Not very elegant, but gets the job done I think.[/color]
            >
            > Thx but it doesn't work: I don't see how I can have the script pause
            > for 1-300 seconds, while still send some empty string to the browser
            > every 5 seconds just to avoid a time-out error. Did I get this wrong?[/color]

            It depends.
            What is the exact reason of your pause?

            Grtz,
            --
            Rik Wasmus


            Comment

            • Vincent Delporte

              #7
              Re: Long sleep() and time-out's

              On Wed, 14 Jun 2006 21:40:08 +0200, "Rik" <luiheidsgoeroe @hotmail.com>
              wrote:[color=blue]
              >What is the exact reason of your pause?[/color]

              I have a main loop that fetches information from another site, but to
              simulate fake users, I need these fetching to occur at random
              intervals, between 1 and 300s. The problem is that after any sleep >
              30 seconds, the browser reports a 504 (time-out).

              Comment

              • Jerry Stuckle

                #8
                Re: Long sleep() and time-out's

                Vincent Delporte wrote:[color=blue]
                > On Wed, 14 Jun 2006 21:40:08 +0200, "Rik" <luiheidsgoeroe @hotmail.com>
                > wrote:
                >[color=green]
                >>What is the exact reason of your pause?[/color]
                >
                >
                > I have a main loop that fetches information from another site, but to
                > simulate fake users, I need these fetching to occur at random
                > intervals, between 1 and 300s. The problem is that after any sleep >
                > 30 seconds, the browser reports a 504 (time-out).[/color]

                A 504 sounds like the browser timing out (although I guess it could be PHP).

                As has been indicated before, you can change the PHP timeout value, but there's
                nothing you can do about the browser.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Vincent Delporte

                  #9
                  Re: Long sleep() and time-out's

                  On Thu, 15 Jun 2006 00:01:42 -0400, Jerry Stuckle
                  <jstucklex@attg lobal.net> wrote:[color=blue]
                  >As has been indicated before, you can change the PHP timeout value, but there's
                  >nothing you can do about the browser.[/color]

                  OK, so it's hopeless. It's a shared PHP server to which I don't have
                  access, so no fiddling with PHP.INI. I'll rewrite this in Delphi
                  instead.

                  Thanks everyone.

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Long sleep() and time-out's

                    Vincent Delporte wrote:[color=blue]
                    > On Thu, 15 Jun 2006 00:01:42 -0400, Jerry Stuckle
                    > <jstucklex@attg lobal.net> wrote:
                    >[color=green]
                    >>As has been indicated before, you can change the PHP timeout value, but there's
                    >>nothing you can do about the browser.[/color]
                    >
                    >
                    > OK, so it's hopeless. It's a shared PHP server to which I don't have
                    > access, so no fiddling with PHP.INI. I'll rewrite this in Delphi
                    > instead.
                    >
                    > Thanks everyone.[/color]

                    If it's a timeout problem in the browser it doesn't matter what language you
                    use. The problem isn't in anything you can control.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Vincent Delporte

                      #11
                      Re: Long sleep() and time-out's

                      On Thu, 15 Jun 2006 23:51:18 -0400, Jerry Stuckle
                      <jstucklex@attg lobal.net> wrote:[color=blue]
                      >If it's a timeout problem in the browser it doesn't matter what language you
                      >use. The problem isn't in anything you can control.[/color]

                      I meant that I would rewrite the algo in Delphi instead of a PHP
                      script. That will solve the sleep(rand()) issue. Thanks.

                      Comment

                      • Andy Jeffries

                        #12
                        Re: Long sleep() and time-out's

                        On Fri, 16 Jun 2006 07:08:31 +0200, Vincent Delporte wrote:[color=blue][color=green]
                        >>If it's a timeout problem in the browser it doesn't matter what language
                        >>you use. The problem isn't in anything you can control.[/color]
                        >
                        > I meant that I would rewrite the algo in Delphi instead of a PHP script.
                        > That will solve the sleep(rand()) issue. Thanks.[/color]

                        Unless I'm missing something Jerry's answer still stands. If you write a
                        server-side CGI exe using Delphi, the browser will still timeout while
                        waiting for your random wait.

                        If you are planning on running the Delphi utility through some other
                        method (at, scheduled jobs, etc) then you could do the same thing with PHP
                        (using set_time_limit( )) and it would work equally fine.

                        Cheers,


                        Andy

                        --
                        Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
                        http://www.gphpedit.org | PHP editor for Gnome 2
                        http://www.andyjeffries.co.uk | Personal site and photos

                        Comment

                        • David Haynes

                          #13
                          Re: Long sleep() and time-out's

                          Andy Jeffries wrote:[color=blue]
                          > On Fri, 16 Jun 2006 07:08:31 +0200, Vincent Delporte wrote:[color=green][color=darkred]
                          >>> If it's a timeout problem in the browser it doesn't matter what language
                          >>> you use. The problem isn't in anything you can control.[/color]
                          >> I meant that I would rewrite the algo in Delphi instead of a PHP script.
                          >> That will solve the sleep(rand()) issue. Thanks.[/color]
                          >
                          > Unless I'm missing something Jerry's answer still stands. If you write a
                          > server-side CGI exe using Delphi, the browser will still timeout while
                          > waiting for your random wait.
                          >
                          > If you are planning on running the Delphi utility through some other
                          > method (at, scheduled jobs, etc) then you could do the same thing with PHP
                          > (using set_time_limit( )) and it would work equally fine.
                          >
                          > Cheers,
                          >
                          >
                          > Andy
                          >[/color]
                          You could always respond to the browser before you go into the sleep
                          loop and redirect it to a 'waiting...' page with a meta-refresh on it.
                          The waiting page can check whether the fetch from the remote is complete
                          and either a) display a new page with the details or b) call itself and
                          loop again.

                          Maybe a c) if we have looped too many times to say 'the data isn't coming'.

                          -david-

                          Comment

                          • Vincent Delporte

                            #14
                            Re: Long sleep() and time-out's

                            On Fri, 16 Jun 2006 20:13:37 GMT, Andy Jeffries
                            <news@andyjeffr ies.co.uk> wrote:[color=blue]
                            >Unless I'm missing something Jerry's answer still stands. If you write a
                            >server-side CGI exe using Delphi, the browser will still timeout while
                            >waiting for your random wait.[/color]

                            No, I meant rewriting this as a Delphi client app instead of a PHP
                            script. Too bad that the whole thing breaks because I didn't think
                            about the sleep() thing. No biggie though. Thanks everyone for your
                            help.

                            Comment

                            • Vincent Delporte

                              #15
                              Re: Long sleep() and time-out's

                              On Fri, 16 Jun 2006 16:20:42 -0400, David Haynes
                              <david.haynes2@ sympatico.ca> wrote:[color=blue]
                              >You could always respond to the browser before you go into the sleep
                              >loop and redirect it to a 'waiting...' page with a meta-refresh on it.
                              >The waiting page can check whether the fetch from the remote is complete
                              >and either a) display a new page with the details or b) call itself and
                              >loop again.
                              >
                              >Maybe a c) if we have looped too many times to say 'the data isn't coming'.[/color]

                              Thanks a bunch for the idea, but it's just too complicated. I'll be
                              done in Delphi this week-end :-)

                              Comment

                              Working...