How to remove the comment with the page execution time

Published on and tagged with cakephp  faq  tip

If you look at the HTML source of pages generated with CakePHP, you will probably detect a comment with the page execution time after the </html> tag that looks like:

<!-- 0.6885s -->

This comment is automatically added by Cake if the debug value in app/config/core.php is greater than 0.

As long as you only work with HTML in your views, this is no problem. But if you have to use a different format like JSON, you won’t love this comment and you have to get rid of it ;-)

There are two ways to accomplish this.

The first approach is to set the debug value to 0, for example in a single action, with:

Configure::write('debug', 0);

The other approach is to remove the code snippet which adds the comment with the page execution time. For this purpose open app/webroot/index.php, and at the end of the file remove the following code:

if (Configure::read() > 0) {
    echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";

Happy baking!

19 comments baked

Bake a comment

(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License