0

Is there anyway to check PHP PDO Query running in PHP while loop's time? Like for example the user needs to update their information depending on the data they have it can take either 30 seconds or 3 minutes. I'd like to display that to the user before they attempt to run the while loop query.

Game Lover
  • 27
  • 2
  • No, I don't think so. You might be able to guess, but you never know how long something will run until you actually run it. – Alexander O'Mara Mar 26 '16 at 06:02
  • If you keep metrics, and you have them stored in such a way that you can query them, then I suppose it would be possible to generate a reasonable estimate. Without that the best one could do would be to make a guess. – Sverri M. Olsen Mar 26 '16 at 06:10
  • It was worth a shot asking but Trevor's reply seems like a good method. – Game Lover Mar 26 '16 at 06:16

1 Answers1

0

There is no way to do this accurately.

If you are doing this locally on your PC, it would depend on your computer specs, the computer's load at that time, etc.

If you are doing it from client to server (ie: user connecting to your website that is hosted on a server) it would depend on your internet connection, the speed of your computer, the speed of the server, the current loads of both devices.

Basically, there are too many variables to take into account, and you would never get a precise estimate.

However You could always give rough estimates based on a few tests...

On your computer you can do a test running the loop 10, 30, 50, ect times, and use this post to measure how long it takes:

$start = microtime(true);
while (...) {

}
$time_elapsed_secs = microtime(true) - $start;

Then on the final version of your code... depending on how many times the code is going to loop you can use your results to give your user a rough estimate of how long it will take.

Community
  • 1
  • 1
Trevor Clarke
  • 1,482
  • 1
  • 11
  • 20