@@ -33,6 +33,8 @@ class Command
33
33
protected $ _stdout = null ;
34
34
protected $ _stderr = null ;
35
35
protected $ _callback = null ;
36
+ protected $ _timestart = null ;
37
+ protected $ _timeend = null ;
36
38
protected $ _cwd = null ;
37
39
protected $ _env = null ;
38
40
protected $ _conf = array ();
@@ -189,6 +191,7 @@ public function run($stdin = null)
189
191
$ this ->_exitcode = null ;
190
192
$ this ->_stdout = null ;
191
193
$ this ->_stderr = null ;
194
+ $ this ->_timestart = microtime (true );
192
195
193
196
// Prepare the buffers structure
194
197
$ buffers = array (
@@ -197,9 +200,10 @@ public function run($stdin = null)
197
200
2 => &$ this ->_stderr ,
198
201
);
199
202
$ this ->_exitcode = self ::exec ($ this ->getFullCommand (), $ buffers , $ this ->_callback , $ this ->_cwd , $ this ->_env , $ this ->_conf );
203
+ $ this ->_timeend = microtime (true );
200
204
201
205
if ($ this ->_throw && $ this ->_exitcode !== 0 ) {
202
- throw new CommandException ($ this , "Command failed ' " . $ this -> getFullCommand (). " ': \n" .trim ($ this ->getStdErr ()));
206
+ throw new CommandException ($ this , "Command failed ' $ this ': \n" .trim ($ this ->getStdErr ()));
203
207
}
204
208
205
209
return $ this ;
@@ -250,6 +254,17 @@ public function getStdErr()
250
254
return $ this ->_stderr ;
251
255
}
252
256
257
+ /**
258
+ * Gets the duration of the command execution
259
+ *
260
+ * @param bool $microseconds If true, return microseconds (float), otherwise seconds (int)
261
+ * @return int|float
262
+ */
263
+ public function getDuration ($ microseconds =false )
264
+ {
265
+ $ duration = $ this ->_timeend - $ this ->_timestart ;
266
+ return $ microseconds ? $ duration : round ($ duration );
267
+ }
253
268
254
269
/**
255
270
* Executes a command returning the exitcode and capturing the stdout and stderr
0 commit comments