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

Latest comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesnโ€™t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.