phpcodeigniter-3benchmarking

Why doesn't elapsed_time() work from log_message() even if called from post_system hook?


If I try to log benchmark->elapsed_time() in post_system hook, it just logs {elapsed_time} as if I called it from a controller.

CodeIgniter documentation says: "post_system Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser."

It also says you are supposed to echo the elapsed_time() in a view to show it to the user, but... how is it possible that elapsed_time() is still being calculated after sending the finalized data to the browser? I feel being lied to.

People keep saying I should use my own marks and get the difference, but that's not the same as using this...


Solution

  • Turns out the documentation also says:
    "If the first parameter is empty this function instead returns the {elapsed_time} pseudo-variable. This permits the full system execution time to be shown in a template. The output class will swap the real value for this variable."

    I went to the Output class and found the 2 marks it is using: total_execution_time_start and total_execution_time_end and I can use those in the post_system hook.