Re: microtime questions
| From: | Joe Wollard | Date: | Fri, 07 Apr 2006 17:35:58 +0000 |
| Subject: | Re: microtime questions | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233455@lists.php.net to get a copy of this message | ||
Tedd,
The only way that I can even think of this as being possible is if you call
microtime() instead of microtime(true). The former will return 'msec sec'
separated by a space which can produce a negative number because you've
essentially got two different types of measurements there. IMHO PHP should
probably throw out an error when two strings are used in a mathematical way
- in this case (without the TRUE arg) here is a possible equation that could
be evaluated.
0.15290800 1144430717
- 0.86641600 1144430716
PHP evaluates this to -0.713508 (or 0.15290800 - 0.86641600) It's negative
because we're not talking about msecs from the same second - it ignores the
seconds and only pays attention to the microseconds. So if you're using
microtime(true) how can this happen on your machine? Well, off the top of my
head I think you should verify that your machine (or your hosting service)
is running PHP5 || >. IF not, and error reporting is turned off, then you'll
get a negative number from time to time since the seconds are being ignored..
http://php.net/microtime has an example of how to emulate
microtime(true) on
PHP < 5
Hope that helps!
-Joe
On 4/7/06, Brad Bonkoski <bbonkoski@mediaguide.com> wrote:
>
> How is the CPU not in question? Does this script run on air?
> It may not be YOUR CPU, but it is still a CPU bound by the sceduling
> algorithm of the Operating System, so the time differentials are too be
> expected.
> -B
>
> tedd wrote:
>
> > At 12:24 PM -0400 4/7/06, Brad Bonkoski wrote:
> >
> >> Interesting...
> >> as for your first question...
> >> Know that PHP/Apache does not have free reign to your CPU, so the
> >> times could be different based on the scheduling going on in the OS
> >> kernel.
> >>
> >> As for the second one...
> >> No idea why you would get a negative number, I just copied and ran
> >> from the command line and did not encounter 1 negative time for about
> >> 30 runs....
> >>
> >> Do you get negative times if you run it from the command line as well?
> >> -B
> >>
> >>> RE:
> >>>
> >>> http://www.xn--ovg.com/microtime.php
> >>>
> >
> > Brad:
> >
> > Thanks for looking.
> >
> > My questions are with regard to what happens on the site, not via my
> > command line. As such, my command line and my CPU are not involved.
> >
> > Can you answer the questions as they pertain to the site in question?
> >
> > Thanks.
> >
> > tedd
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>