DEV Community

Morcos Gad
Morcos Gad

Posted on

Calculate Time with microtime() PHP - Laravel

Let's start quickly and I found something interesting. If we want according to the duration of a certain operation in seconds in laravel it is possible to use the microtime function which accepts the value of float Let's see the example

$startTime = microtime(true);

//do something...
\App\User::all();

$seconds = number_format((microtime(true) - $startTime) * 1000, 2);
echo $seconds . ' seconds'; //19.35 seconds
Enter fullscreen mode Exit fullscreen mode

I hope it helps you in some of your future projects
Source :- https://www.youtube.com/watch?v=nMTb8fUTvE4

Discussion (0)