It is echoing zero every time. I am not sure if the query was that fast or something is wrong. Code; PHP: public function onRun() { $starttime = microtime(true); $db = new Database(); $uuid = $this->uuid; $query = "SELECT coins FROM players WHERE uuid='$uuid';"; $result = $db->query($coins ); $coins = 0; while ($row = $result->fetch_assoc()) { $coins += $row["coins "]; } $this->setResult($balance); $endtime = microtime(true); $duration = $endtime - $starttime; $hours = (int)($duration/60/60); $minutes = (int)($duration/60)-$hours*60; $seconds = (int)$duration-$hours*60*60-$minutes*60; $ms = (int)$seconds*1000; echo "\n".$seconds; } Btw, I have over 1000 rows created I am hosting locally.. is that why?
The most likely answer is that the task is executing in less than a second. In addition, you have a line PHP: (int) $seconds * 1000 should be replaced with PHP: (int) ($seconds * 1000) to avoid problems with operator precedence.
PHP: //somewhere$task = new BalanceAsyncTask($uuid, microtime(true));$this->getServer()->getAsyncPool()->submitTask($task); PHP: //on the taskpublic function onCompletion(Server $server){ echo "Time Took: " . microtime(true) - $this->microtime;}
He wants to measure the time for the query() function to run. It makes no sense to measure how long it took to get picked up by the async pool.
microtime(true) already returns it in seconds, i dont understand why you need to go all the way to calculate it again PHP: $seconds = $endtime - $starttime;$ms = $seconds * 1000;