DEV Community

Morcos Gad
Morcos Gad

Posted on

3 1

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

Top comments (0)

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Value this insightful article and join the thriving DEV Community. Developers of every skill level are encouraged to contribute and expand our collective knowledge.

A simple “thank you” can uplift someone’s spirits. Leave your appreciation in the comments!

On DEV, exchanging expertise lightens our path and reinforces our bonds. Enjoyed the read? A quick note of thanks to the author means a lot.

Okay