View Full Version : Tell how long a script is running for?

04-19-2003, 07:10 PM
Is there any way to tell how long a script has been running for?

04-21-2003, 09:39 AM

I'm not sure what you mean. Do you mean the time required for a page to load? If so...

At the top of the page:

$thing = microtime();

at the bottom of the page:

print "This script took " . microtime()-$thing . " seconds to load.";

04-21-2003, 10:20 AM
That would be the best way...

If you wanted to calculate the time taken to do a query on a database or something like that, you would just put the same around the particular part of the code.

04-21-2003, 07:58 PM
I wanted a notification after a certain amount of time. Do I have to kepp on checking the time? Or is there a way that doesn't put as much of a load on the server?

04-21-2003, 08:01 PM
Seeing as PHP is run on the server, I wouldnt have thought that you could notify half way through, cos It parses everything before the page is returned.

04-21-2003, 08:38 PM
By default timeout=30s. I want at 29.5 seconds for it to execute a simple function, like:

function pagetimeout() {
exit ("Awww, Dang! We ran outta time!");

by notify, i mean tell the remainder of the script that it is about to TO.