Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Plugin request: show runtime
Hi… i think i may have inquired about this many months ago..
but i’ve not since come across anytihng in its regard… i’m just wondering if anyone might be interested in putting together a plugin that would allow for a tag to display the page runtime that is currently commented out in textpattern/index.php. it’s not a hugely important thing to have, by any means, but it might be a nice thing to have… :)
textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation
Offline
Re: Plugin request: show runtime
> alicson wrote:
> Hi… i think i may have inquired about this many months ago..
but i’ve not since come across anytihng in its regard… i’m just wondering if anyone might be interested in putting together a plugin that would allow for a tag to display the page runtime that is currently commented out in textpattern/index.php. it’s not a hugely important thing to have, by any means, but it might be a nice thing to have… :)
Its always in the source of the rendered document and you could extract the variable in a plugin with ease!
Offline
#3 2004-11-07 22:01:22
- Andrew
- Plugin Author

- Registered: 2004-02-23
- Posts: 730
Re: Plugin request: show runtime
Look for this line in <code>publish.php -> function textpattern()</code>:
<pre>
$microdiff = (getmicrotime() – $microstart);
echo n,comment(‘Runtime: ‘.substr($microdiff,0,6));
</pre>
Offline
#4 2004-11-07 22:23:30
- zem
- Developer Emeritus

- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: Plugin request: show runtime
Actually it’s quite tricky to display the runtime from a plugin or PHP fragment, becuase the page hasn’t finished rendering when the plugin code is executed.
Alex
Offline
Re: Plugin request: show runtime
Hmm, looking at how to do this, and I don’t see an obvious way, but I’m by far no authority on plugin authoring.
This code in the textpattern() function in publish.php does the work:
$microdiff = (getmicrotime() - $microstart);
echo n,comment('Runtime: '.substr($microdiff,0,6));
But it’s the very last thing to happen when rendering a page. $microdiff is set after all plugins have done their work and all the html has been rendered.
Also $microdiff is not a global, so we don’t seem to have access to it from a plugin.
Now one could write a plugin that takes $microstart and does the same math thats done at the end of textpattern(), but there will still be more code executing after that, so the count will not be as accurate.
Offline
#6 2004-11-07 23:50:16
- Andrew
- Plugin Author

- Registered: 2004-02-23
- Posts: 730
Re: Plugin request: show runtime
Perhaps if you use the multipass plugin and set the final $microdiff as a global variable? Seems like more trouble than it’s worth tho.
Offline
Re: Plugin request: show runtime
;) okay… not that big a deal… i think Dean had said at one point that he’d make it possible to uncomment in a future release… thank you guys much for considering, though.
textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation
Offline
#8 2005-02-14 00:43:43
- pencilneck
- Member

- From: Daarsit
- Registered: 2004-08-10
- Posts: 10
Re: Plugin request: show runtime
just remove teh ‘n,comment’ bit and you are good to go. You can even style it like this:
<pre>echo “<div id=\“yourdiv\”>\n”;
echo (‘Runtime: ‘.substr($microdiff,0,6));
echo “</div>\n”;
</pre>
Last edited by pencilneck (2005-02-14 00:45:07)
Offline
#9 2005-02-14 02:49:08
- Andrew
- Plugin Author

- Registered: 2004-02-23
- Posts: 730
Re: Plugin request: show runtime
…and you’ll end up with a <code><div></code> after the <code></html></code> tag of your document. I think what alicson was requesting was a way to grab hold of that value and use it somewhere else, like in a form or template, which is not possible.
Offline
Re: Plugin request: show runtime
Why don’t you put a little PHP code in your page?
At the top of my default page I have:
<pre>
<code>
$time = explode(” “, microtime());
$start = $time1 + $time0;
</code>
</pre>
and then at the end…
<pre>
<?php
$time = explode(” “, microtime());
$finish = $time1 + $time0;
?>
Page loaded in <?php echo ($finish – $start); ?> seconds.
</pre>
OR
You can do it in Javascript, which should give a more realistic load time, especially if you have any images or a lot of external scripts/css.
In your <head></head> section, put:
<pre>
<script language=‘javascript’ type=‘text/javascript’>
var start = new Date();
function setLoadTime() {
var end = new Date();
var pageLoad = String(end.getSeconds()) + ‘.’ + String(end.getMilliseconds());
pageLoad -= (String(start.getSeconds()) + ‘.’ + String(start.getMilliseconds()));
Somewhere in your body where you want the time to show up, add <span id="pageLoadTime"> </span>.
Lastly, in your <body> tag, set your onLoad attribute to “setLoadTime();”:
<pre>
<body onLoad=“setLoadTime();”>
</pre>
-Steve
Edit: *#$& DAMN I hate posting code on this board.
Last edited by supa (2005-02-14 03:26:49)
Offline
#11 2005-02-14 04:12:36
- Andrew
- Plugin Author

- Registered: 2004-02-23
- Posts: 730
Re: Plugin request: show runtime
<em>*#$& DAMN I hate posting code on this board</em>
yes, agreed
Last edited by Andrew (2005-02-14 04:12:47)
Offline
#12 2005-02-14 09:52:20
- pencilneck
- Member

- From: Daarsit
- Registered: 2004-08-10
- Posts: 10
Re: Plugin request: show runtime
oops my bad, well at least I know the proper way to do it now, thanks guys.
Offline
Pages: 1