Heya,
Alweer een class, copyright graag laten staan. Donaties zijn altijd welkom
Gebruik:
Alweer een class, copyright graag laten staan. Donaties zijn altijd welkom
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/**
* Timer Class
* Counts the time needed to load the page
*
* @author Rik S.
* @copyright Copyright (c) Rik S. All rights reserved.
*/[/COLOR]
[URL="http://www.php.net/class"]class[/URL] timer
[COLOR= #007700]{[/COLOR]
[COLOR= #FF8000]/**
* Holds the starting time
*
* @var int
*/[/COLOR]
[URL="http://www.php.net/private"]private[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$intStart[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]/**
* Holds the stopping time
*
* @var int
*/[/COLOR]
[URL="http://www.php.net/private"]private[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$intStop[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]/**
* Start the timer
*/[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] startTime[COLOR= #007700]()
{[/COLOR]
[COLOR= #0000BB]$tempTime[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000] [/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/microtime"]microtime[/URL][COLOR= #007700]());[/COLOR]
self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$intStart[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$tempTime[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]] +[/COLOR] [COLOR= #0000BB]$tempTime[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]];
}[/COLOR]
[COLOR= #FF8000]/**
* Stop the timer
*/[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] stopTime[COLOR= #007700]()
{[/COLOR]
[COLOR= #0000BB]$tempTime[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000] [/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/microtime"]microtime[/URL][COLOR= #007700]());[/COLOR]
self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$intStop[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$tempTime[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]] +[/COLOR] [COLOR= #0000BB]$tempTime[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]];
}[/COLOR]
[COLOR= #FF8000]/**
* Show how much time the script needed to execute, rounded by 4 digits.
*
* @param int $intRound
* @return int
*/[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] showTime[COLOR= #007700]([/COLOR][COLOR= #0000BB]$intRound[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]4[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$intStop[/COLOR][COLOR= #007700]))
{[/COLOR]
[COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]stopTime[COLOR= #007700]();
}[/COLOR]
[COLOR= #0000BB]$tempTime[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$intStop[/COLOR] [COLOR= #007700]-[/COLOR] self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$intStart[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/return"]return[/URL] self[COLOR= #007700]::[/COLOR]roundTime[COLOR= #007700]([/COLOR][COLOR= #0000BB]$tempTime[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$intRound[/COLOR][COLOR= #007700]);
}[/COLOR]
[COLOR= #FF8000]/**
* Rounds the time to the given number of digits
*
* @param int $intTime
* @param int $intRound
* @return int
*/[/COLOR]
[URL="http://www.php.net/private"]private[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] roundTime[COLOR= #007700]([/COLOR][COLOR= #0000BB]$intTime[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$intRound[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/round"]round[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$intTime[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$intRound[/COLOR][COLOR= #007700]);
}
}[/COLOR]
?> Gebruik:
[COLOR= #0000BB]<?php[/COLOR]
Timer[COLOR= #007700]:[/COLOR]SMILEYYYYYYYYYYYBEGIN[COLOR= #007700]:[/COLOR]startTime[COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/sleep"]sleep[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]);[/COLOR]
Timer[COLOR= #007700]:[/COLOR]SMILEYYYYYYYYYYYBEGIN[COLOR= #007700]:[/COLOR]stopTime[COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000] Script took [/COLOR] [COLOR= #007700].[/COLOR] Timer[COLOR= #007700]:[/COLOR]SMILEYYYYYYYYYYYBEGIN[COLOR= #007700]:[/COLOR]showTime[COLOR= #007700]() .[/COLOR] [COLOR= #DD0000] seconds to load[/COLOR][COLOR= #007700];[/COLOR]
?>
.ff probere