How much execution time is left?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mikhail Kovalev

    How much execution time is left?

    I'm using set_time_limit( ) to set maximum execution time. Is there a
    way to check how much time is left at any time during the execution
    itself?
  • =?ISO-8859-1?Q?thib=B4?=

    #2
    Re: How much execution time is left?

    Mikhail Kovalev wrote:
    I'm using set_time_limit( ) to set maximum execution time. Is there a
    way to check how much time is left at any time during the execution
    itself?
    Use time() or microtime() at the beginning of the script and store the
    value. Later, call it again and substract the start time, you'll get the
    elapsed time. Another substraction of the time limit by the elapsed time
    will give you the remaining time.

    -thib´

    Comment

    • Jerry Stuckle

      #3
      Re: How much execution time is left?

      thib´ wrote:
      Mikhail Kovalev wrote:
      >I'm using set_time_limit( ) to set maximum execution time. Is there a
      >way to check how much time is left at any time during the execution
      >itself?
      >
      Use time() or microtime() at the beginning of the script and store the
      value. Later, call it again and substract the start time, you'll get the
      elapsed time. Another substraction of the time limit by the elapsed time
      will give you the remaining time.
      >
      -thib´
      >
      Not true.

      set_time_limit is the limit for execution time. time() or microtime()
      is real time. A huge difference.

      For instance - say you have a time limit of 30 seconds. One second into
      your script, a high priority process gets invoked and runs for two minutes.

      You still have about 29 seconds left left on your script, but the time()
      or microtime() function says you're 1 minute, 31 seconds over.

      An extreme example, I know. But it gets the point across.

      So no, there is no way to tell how much time is left.

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

      Comment

      • Michael Fesser

        #4
        Re: How much execution time is left?

        ..oO(thib´)
        >Mikhail Kovalev wrote:
        >I'm using set_time_limit( ) to set maximum execution time. Is there a
        >way to check how much time is left at any time during the execution
        >itself?
        >
        >Use time() or microtime() at the beginning of the script and store the
        >value. Later, call it again and substract the start time, you'll get the
        >elapsed time. Another substraction of the time limit by the elapsed time
        >will give you the remaining time.
        This won't work. In addition to Jerry's example a quote from the manual:

        | Note: The set_time_limit( ) function and the configuration directive
        | max_execution_t ime only affect the execution time of the script
        | itself. Any time spent on activity that happens outside the execution
        | of the script such as system calls using system(), stream operations,
        | database queries, etc. is not included when determining the maximum
        | time that the script has been running.

        Micha

        Comment

        • Rob

          #5
          Re: How much execution time is left?

          On Feb 9, 3:42 pm, Michael Fesser <neti...@gmx.de wrote:
          .oO(thib´)
          >
          Mikhail Kovalev wrote:
          I'm using set_time_limit( ) to set maximum execution time. Is there a
          way to check how much time is left at any time during the execution
          itself?
          >
          Use time() or microtime() at the beginning of the script and store the
          value. Later, call it again and substract the start time, you'll get the
          elapsed time. Another substraction of the time limit by the elapsed time
          will give you the remaining time.
          >
          This won't work. In addition to Jerry's example a quote from the manual:
          >
          | Note: The set_time_limit( ) function and the configuration directive
          | max_execution_t ime only affect the execution time of the script
          | itself. Any time spent on activity that happens outside the execution
          | of the script such as system calls using system(), stream operations,
          | database queries, etc. is not included when determining the maximum
          | time that the script has been running.
          >
          Micha
          True, but in general terms, Thib's solution should work - unless
          Mikhail knows beforehand that there will be a lot of non-PHP
          processing going on, i.e. file transfers.

          Rob.

          Comment

          • =?ISO-8859-1?Q?thib=B4?=

            #6
            Re: How much execution time is left?

            Michael Fesser wrote:
            .oO(thib´)
            >
            >Mikhail Kovalev wrote:
            >>I'm using set_time_limit( ) to set maximum execution time. Is there a
            >>way to check how much time is left at any time during the execution
            >>itself?
            >Use time() or microtime() at the beginning of the script and store the
            >value. Later, call it again and substract the start time, you'll get the
            >elapsed time. Another substraction of the time limit by the elapsed time
            >will give you the remaining time.
            >
            This won't work. In addition to Jerry's example a quote from the manual:
            >
            | Note: The set_time_limit( ) function and the configuration directive
            | max_execution_t ime only affect the execution time of the script
            | itself. Any time spent on activity that happens outside the execution
            | of the script such as system calls using system(), stream operations,
            | database queries, etc. is not included when determining the maximum
            | time that the script has been running.
            >
            Micha
            Good to know, thanks.

            So, a not absolutely reliable way would be to stop the counter before every
            'heavy' instruction and restart it again just after it, right?
            I've seen some tiny handy "stopwatch" functions that could make the job
            without too much complications.

            Anyway, is it really worth it, Mikhail?

            -thib´

            Comment

            • bio-anomoly

              #7
              Re: How much execution time is left?

              There is a system resource call where PHP will admit how much system
              time and user time has been used.

              If you use lots of sleeps, freads, and cURLs, etc, you use very little
              system time.

              I have executed scripts on Godaddy websites [default CPU time 30
              seconds] which are heavily waited, but the scripts are still
              terminated after 15-20 minutes. I guess there is a dead-mans-handle.

              Comment

              Working...