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...

$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 :-

Oldest comments (0)

Advice For Junior Developers

Advice from a career of 15+ years for new and beginner developers just getting started on their journey.