Show PHP rendertime on page

I’ve created a [little snippet][1]… plugin… how do you call it :slight_smile: that calculates and show the rendertime of every page.

Disclaimer - I created it very quickly and did not always follow the Kirby Guidelines for implementing this little snippet… so do try this at home, not at work or development first :stuck_out_tongue:


The “plugin” takes two variables;

  1. Where / how to show the rendertime.
  2. What text is used to show the rendertime.

The first option has three basic values;

A. Show in the footer

B. Show in the html-source

C. Show on the browser tab- titlebar


Add a custom-field to your site-blueprint like this;

   label: Rendertime
   type:  text
   default: (rendertime:1 text:page rendered in @ seconds)```
This will output something like below at your sites-panel page;

<img src="//" width="646" height="237">

As you can see in the helper-tag, the key "**rendertime**" accepts several values (numeric only)

-  1 : show rendertime in code
-  3 : show rendertime in page
-  5 : show rendertime on tab

You can also take the sum of these individual numbers;

 - 1 and 3 = 4 : this will show the rendertime in both pag and code
 - 1 and 5 = 6 : this will show it in code and on tab
 - 1 and 3 and 5 = 9 : this will show it all over the place
 - etc...

The key "**text**" is the string that is returned, while the "**@**" character is replaced with the actual rendertime.
Installation is simple, jump to the **[GitHub-page][2]** and download the **[.zip-file][3]** that includes the directory-structure.

Alternatively you can create this folder: ```\site\tags\``` and place the file "**rendertime.php**" in it.

When you have setup the blueprint for your site (so you can get the rendertime site-wide, and not only at a specific page), you have to alter the header- and footer of your site.

This is mostly done in the "**header.php**" and "**footer.php**" snippet.

Simply add ```<?php rendertime('start'); ?>``` at the very first line of your html-header-template (even before the &lt;html> tag).

Navigate to the footer, and place ```<?php rendertime($site->rendertime()->kt()); ?>``` just before the closing &lt;/body> tag of your html-template.

Now everything is done;

- You have the "**rendertime.php**" file in your "**tag**" folder.
- You have setup the blueprint for your site, where you can change the default settings.
- You have placed the **start-** and the **endcode** which the snippet needs to calculate the rendertime.


Instead of using a Kirbytag I’d recommend using configuration options (c::set in the config file and c::get in your plugin).

Also: What is the use-case for this? I think it only makes sense while developing the site anyway.

Use-case is development… I need / want to know how much impact some code-changes do have on my sites performance.

Using this snippet, I can see the effects on the fly…

And I’m migrating two Wordpress-sites to Kirby, they have the same snippet - so I can compare the speed of a Kirby-page with the exact same page, rendered in Wordpress (same server, same content, same design, etc…).

Alright. Because the plugin is only being used for development, it makes even more sense to store the configuration in the config file (even a host-specific one for your development host), not in the content.

You made 4 plugins… in 4 days.
You are like a weasel, or like a car without breaks. :smiley: :wink:

I made even more, but did not publish them :smile:

Been explorer Kirby for a week now, really love it!


Hey @dMOTION , great plugin!.

I’ve made a new class of this plugin based on yours, but using the Kirby coding style guidelines and a config.php file for the development environment.

Please, check out the following Gist

You only need put the following variables on your config.php of your development environment:

  'rendertime'        => true,
  'rendertime.type'   => 1,
  'rendertime.format' => 'Page rendered in {totaltime} seconds @ {rendertime}',

And this in your header:

<?php RenderTime::start() ?>

<!DOCTYPE html>

And this in your footer:

<?php RenderTime::end() ?>

I’ve omitted the tag part, That’s great for templates, but I think is not necessary for production.

That’s really great!

I can learn a lot of your code :smile:

When I created my version, I knew Kirby for less than a week… so my code was actually some kind of a code-doodle…

Now I see you code, I can imagine way better how to write my new / next plug-ins, thanks!

It’s very interesting to have access to your rendertime; because you can compare it against something like Wordpress, or see on the fly what code-changes / content-changes do to your server- / page-performance!

Maybe we should also change the timestamp;

$rendertime = date('Y/m/d - H:i:s', time());

(I re-ordered the Y/m/d, so the format is more universal - I originally used a European format, but maybe the American standard is better to follow).

1 Like

i’ve hacked index.php to get redertime and memory usage:

first line:

//.oO measure used time/mem... get start time
$time_start = microtime(true);

then kirby-stuff…

and the last line:

//.oO measure used time/mem... dump stats if kirby debug is on
e(c::get('debug'), '<hr><b>Memory usage:</b> ' . round(memory_get_usage(true)/1024/1024,2) . ' Megabytes<br><b>Total Execution Time:</b> ' . (round((microtime(true) - $time_start)*1000)/1000) . ' Seconds');

The memory-usage is a nice addition!

But I did fiddle around with it (in my own original code, a week ago) and some shared servers did not allow access to memory_get_usage(true); resulting in a php-error.

So I decided to skip that part, just to be sure.

But it is very nice to have it in the updated plug-in, because the memory-usage is also very important (some cheap server do restrict it, so this way you can keep an eye on it).

I’m very happy to listen that from your part, Please, continues sharing more and more plugins. Kirby Rocks!!..

If you want, please update your repository suggesting my version. I think that plugins like this are very important for the kirby community.

@Svnt I’ll try to find any way to add the “memory usage” keeping in mind what is saying @dMOTION. But first I need to study :blush:

I updated the README.MD file - so it now fowards people to your version / fork :smile:

Great!! and many thanks!! but the initial idea is yours, so I’ve forked your original repo and I’ve created a pull request :grin: