Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to record the time execution of a script in Yii?

Tags:

php

yii

I am developing a timetable system using Yii. All working fine, but how can I get the time execution for a script or action.

For example, I have the action "scheduleOptimize". And I want to know how long does it take to run the action in PHP.

Somebody help me please.

Thanx in advance

like image 984
Nizam Avatar asked Jan 13 '14 13:01

Nizam


People also ask

What is Active Record in yii?

Active Record automatically maintains the list of dirty attributes. It does so by maintaining an older version of the attribute values and comparing them with the latest one. You can call yii\db\ActiveRecord::getDirtyAttributes() to get the attributes that are currently dirty.

What is difference between Yii and Yii2?

Conceptually Yii1 and Yii2 are quite similar, however Yii2 runs on newer PHP versions and utilizes namespaces, traits etc. Yii2 has also support for dependency injection through $container singleton available after initializing the framework.

How to register css file in Yii2?

Registering CSS files A CSS file can be registered using the following: $this->registerCssFile("@web/css/themes/black-and-white. css", [ 'depends' => [\yii\bootstrap\BootstrapAsset::class], 'media' => 'print', ], 'css-print-theme'); The above code will add a link to the /css/themes/black-and-white.


3 Answers

Simple snippet, returns execution time in seconds, 5 symbols after comma precision.

   <?php echo sprintf('%0.5f',Yii::getLogger()->getExecutionTime())?>
like image 93
ineersa Avatar answered Oct 05 '22 16:10

ineersa


Yes. You can do with Logging option in yii

Refer this link.

http://www.yiiframework.com/doc/guide/1.1/en/topics.logging

you can do:

  1. Message Logging
  2. Message Routing
  3. Message Filtering
  4. Logging Context Information
  5. Performance Profiling
  6. Profiling SQL Executions
like image 31
Kumar V Avatar answered Oct 05 '22 18:10

Kumar V


You don't need Yii to do it for you. Use native PHP.

$start_time = microtime(true); 

//Do you stuff here
do_stuff('here');

$end_time = microtime(true);

//dividing with 60 will give the execution time in minutes other wise seconds
$execution_time = ($end_time - $start_time)/60;
like image 43
crafter Avatar answered Oct 05 '22 18:10

crafter