Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7843071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:27:52+00:00 2026-06-02T16:27:52+00:00

I want to make a status page for my application using symfony2 where I

  • 0

I want to make a status page for my application using symfony2 where I want to print the execution time (along with other data) of the particular request. I could not find anyway to do this.

I know that I can track the execution time of a code part with:

$starttime = microtime();
// do something
$duration = microtime() - $starttime;

But for obvious reason I cannot place it in the controller, as the whole bootstrap would be not tracked. Also rendering the template would not be included.

Is there any way to get as near as possible to the total execution time of the script?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:27:53+00:00Added an answer on June 2, 2026 at 4:27 pm

    I found a way which I think is ok for our use case. I created a new file performance.php in the web folder which looks like this:

    <?php
    /**
     * This file is only used for doing realtime performance measurement
     * Right now only the microtime is calculated, but in the future the
     * xhproof module could be used: http://de2.php.net/manual/en/book.xhprof.php
     *
     * MAKE SURE TO NOT USE THIS FILE IN PRODUCTION FOR OTHER STUFF THAN REAL TIME
     * PERFORMANCE MEASUREMENT
     */
    
    $GLOBALS['PerformanceTwigExtensionMicrotime'] = microtime(true);
    
    require_once __DIR__.'/app.php';
    

    I also registered a twig extension which uses the global and calculates the elapsed time:

    <?php
    
    namespace Acme\DemoBundle\Extension;
    
    class PerformanceTwigExtension extends \Twig_Extension {
    
        public function getFunctions() {
            return array(
                'performance_exectime' => new \Twig_Function_Method($this, 'getExecTime')
            );
        }
    
        public function getExecTime() {
            if (!isset($GLOBALS['PerformanceTwigExtensionMicrotime'])) {
                return 0;
            }
    
            $durationInMilliseconds = (microtime(true) - $GLOBALS['PerformanceTwigExtensionMicrotime']) * 1000;
            return number_format($durationInMilliseconds, 3, '.', '');
        }
    
        public function getName() {
            return "performance_extension";
        }
    
    }
    

    When we want to do some performance measurements, we can simply use performance.php. The template calls the function and can then display the execution time:

    {{ performance_exectime() }}
    

    It outputs 0 if the start time is not set (e.g. when the normal app.php is used), so it’s safe to use in any case. On the other hand, if someone decides to use performance.php as an entry point, it shouldn’t break anything as only one global variable is different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Heroku to make a php application on Facebook. I want to
I want to make a uiview that can be aware of highlight status, like
I want make datetimepicker in my project. Using jquery how it is possible? I
I want make interactive application where user launches it and can do various task
I am traversing a HTML document using javascript DOM. I want make a list
I am new to ASP. I want to make an ASP page that would
I want to make a php ajax post.(post value without refresh the page) here
I want to make a php ajax post.(post value without refresh the page) here
I want make a bash script which returns the position of an element from
Let's say I want make some of my sources publicly available via my blog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.