Page 1 of 1
microtime();
Posted: Fri Jan 23, 2004 6:25 pm
by dull1554
here's my code
Code: Select all
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
//whole bunch of code.........
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totaltime = ($tend - $tstart);
printf ("<center>page was generated in %f seconds</center>", $totaltime);
here's my question, i want to uses my code to get parse time, but i want to display parse time on the bottom of my menu instead of at the bottom of the page, i have to have the second part of the code at the end of my script to get true parse time, is there a way to printf the time above the second bunch of code?!?!?!?!
not a big deal but i really wanted to do it
Posted: Fri Jan 23, 2004 7:47 pm
by DuFF
A shot in the dark, but maybe you could do something with
ob_start?
(if you've never used it, just so you know, ob=output buffering)
Posted: Fri Jan 23, 2004 7:52 pm
by dull1554
i'll check it out, thanks
Posted: Fri Jan 23, 2004 7:57 pm
by dull1554
i tried doing this but it does not work
Code: Select all
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
ob_start();
printf ("<center>page was generated in %f seconds</center>", $totaltime);
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totaltime = ($tend - $tstart);
ob_end_flush();
any ideas???
Posted: Tue Jan 27, 2004 11:06 am
by Roja
dull1554 wrote:i tried doing this but it does not work
any ideas???
Be more specific on what it did - what do you mean it did not work?
Did it not display? Not display where you wanted it? etc.
Also, if you could provide a link to the rest of the page (phps) we could get more detailed.
Posted: Tue Jan 27, 2004 12:25 pm
by xisle
here's a cool javascript clock if you want to go that way..
just grab the images from the links below...
http://web.developer.tripod.com/elapsed.html
Code: Select all
<table border=0 cellpadding=2 cellspacing=0 bgcolor="">
<tr><td colspan=5><font size=-1>time elapsed:</font></td></tr>
<tr><td align="center" bgcolor="black" height=40><img src="http://web.developer.tripod.com/clock/dg0.gif" name="_mn1"></td>
<td align="center" bgcolor="black" height=40><img src="http://web.developer.tripod.com/clock/dg0.gif" name="_mn2"></td>
<td align="center" bgcolor="black" height=40><img src="http://web.developer.tripod.com/clock/dgc.gif" name="_c"></td>
<td align="center" bgcolor="black" height=40><img src="http://web.developer.tripod.com/clock/dg0.gif" name="_se1"></td>
<td align="center" bgcolor="black" height=40><img src="http://web.developer.tripod.com/clock/dg0.gif" name="_se2"></td></tr>
</table>
<script language="javascript"><!-- start
dg0 = new Image();dg0.src = "http://web.developer.tripod.com/clock/dg0.gif";
dg1 = new Image();dg1.src = "http://web.developer.tripod.com/clock/dg1.gif";
dg2 = new Image();dg2.src = "http://web.developer.tripod.com/clock/dg2.gif";
dg3 = new Image();dg3.src = "http://web.developer.tripod.com/clock/dg3.gif";
dg4 = new Image();dg4.src = "http://web.developer.tripod.com/clock/dg4.gif";
dg5 = new Image();dg5.src = "http://web.developer.tripod.com/clock/dg5.gif";
dg6 = new Image();dg6.src = "http://web.developer.tripod.com/clock/dg6.gif";
dg7 = new Image();dg7.src = "http://web.developer.tripod.com/clock/dg7.gif";
dg8 = new Image();dg8.src = "http://web.developer.tripod.com/clock/dg8.gif";
dg9 = new Image();dg9.src = "http://web.developer.tripod.com/clock/dg9.gif";
dgc = new Image();dgc.src = "http://web.developer.tripod.com/clock/dgc.gif";
hr = 0;
mn = 0;
se = 0;
function dotime(){
theTime=setTimeout('dotime()',1000);
if (se > 59){se=0; mn++;}
if (mn > 59){mn=0; hr++;}
if(hr < 10) {hrs="0"+hr;}
else {hrs=hr;}
if(mn < 10) {mns="0"+mn;}
else {mns=mn;}
if(se < 10) {ses="0"+se;}
else {ses=se;}
tot=hrs+mns+ses;
document._mn1.src = 'clock/dg'+tot.substring(2,3)+'.gif';
document._mn2.src = 'clock/dg'+tot.substring(3,4)+'.gif';
document._se1.src = 'clock/dg'+tot.substring(4,5)+'.gif';
document._se2.src = 'clock/dg'+tot.substring(5,6)+'.gif';
se++;
}
dotime();
//end -->
</script>
Posted: Tue Jan 27, 2004 12:40 pm
by dull1554
sorrymaybe i was not using ob_start and such correctly...it just makes the parse time say 0.000000....
heres the entire source of my index.php file, make with what you wish
http://24.95.139.129/dull1554/showindex.php
thanks again
Posted: Tue Jan 27, 2004 2:42 pm
by pickle
Hmm, the way I would do it is use Javascript. In the menu, create a little element with a certain id, lets say x_id. Then, at the end of your file, output some javascript that changes the contents of x_id (it may be easier to use a form element) to whatever. That way, you can wait until the page is parsed and output before you have to set the element in your menu.
Posted: Tue Jan 27, 2004 3:06 pm
by happz
dull1554 wrote:sorrymaybe i was not using ob_start and such correctly...it just makes the parse time say 0.000000....
When you try to print value of $totaltime you're using an unitialisetd var - so $totaltime has value of 0...
IMHO you should try solution as written above - put some HTML object where you want to have that $totaltime shown, and when finishing page, do something like echo "myObject.value = $totaltime;"
Yes, you have to replace myObject with proper statement (document.getEmelentById(), form., etc) and you have it
happz
Posted: Tue Jan 27, 2004 4:06 pm
by dull1554
i was hoping that there may be a pure php soultion.....but if i have to do it that way i guess i will....thanks a bunch
Posted: Tue Jan 27, 2004 4:10 pm
by pickle
Just had a brainstorm here. What if throughout the page, you don't echo any HTML, but just store it in variables. Then, when the page is parsed and ready to go, you can set your time variable which will change the HTML you've generated, and output all the variables that you've already created. All the work except actually echoing the code will be done while you're timing. This may be quite messy (in fact I'm almost positive it is), but it would work.
Posted: Tue Jan 27, 2004 10:16 pm
by partiallynothing
Can we have the WHOLE page code. Depending on how it is layed out, pickle's idea may work...
Posted: Wed Jan 28, 2004 7:03 pm
by dull1554