Created
September 20, 2013 18:09
-
-
Save JamoCA/6641440 to your computer and use it in GitHub Desktop.
This is a ColdFusion Custom Tag to replace the native CFTimer function. I can't seem to get CFTimer to work even though it's enabled in the ColdFusion Administrator, debugging is enabled and my IP is whitelisted. I also added the ability to display the time based on an IP address mask. (NOTE: I've added this functionality to a basic myTimer tag …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfsetting enableCFOutputOnly="Yes"><!--- | |
Author: James Moberg | |
Date: 9/20/2013 | |
Notes: Called like cftimer but without enabling debugging. (NOTE: "debug" mode not supported.) | |
Types: outline (default), | |
Added "AllowedIPs". Enter a list of IPs. Masks acceptable (127.0.0.1,192.168.*.*) | |
CREDITS: Initial "myTimer" CFTag by Chris Phillips ( http://www.cfchris.com/cfchris/index.cfm/2007/4/5/My-CFTIMER-Custom-Tag ) | |
CFTIMER FUNCTION: https://learn.adobe.com/wiki/display/coldfusionen/cftimer | |
EXAMPLE USAGE | |
<cf_timer label="Sleep Test" type="outline"> | |
<!--- Do some stuff ---> | |
<cfset sleep(50)> | |
</cf_timer> | |
STORE EXECUTION TIME (MILLISECONDS) AS VARIABLE "variables.TimeLapsed" | |
<cf_timer variable="TimeLapsed"> | |
<!--- Do some stuff ---> | |
<cfset sleep(50)> | |
</cf_timer> | |
<cfoutput><p>Time Lapsed = #TimeLapsed# ms</p></cfoutput> | |
STORE EXECUTION TIME (MILLISECONDS) AS VARIABLE "variables.TimeLapsed" | |
<cf_timer allowedips="127.0.0.1,192.168.*.*"> | |
<!--- Do some stuff ---> | |
<cfset sleep(50)> | |
</cf_timer> | |
<cfoutput> | |
---> | |
<cfparam name="attributes.label" default="cftimer"> | |
<cfparam name="attributes.type" default="outline"><!--- comment, inline, outline ("debug" not supported) ---> | |
<cfparam name="attributes.variable" default=""> | |
<cfparam name="attributes.allowedIPs" default=""> | |
<cfsetting enablecfoutputonly="No"> | |
<cfif thistag.executionmode is "Start"> | |
<cfset variables.startTimer = getTickCount()> | |
<cfelseif thistag.executionmode is "End"> | |
<cfif len(attributes.allowedIPs)> | |
<cfset IPAddress = cgi.remote_addr> | |
<cfset validIP = 0> | |
<cfloop index="i" from="5" to="1" step="-1"> | |
<cfif i lt 5> | |
<cfset IPAddress = listsetat(IPAddress, i, "*", ".")> | |
</cfif> | |
<cfif listfind(attributes.allowedIPs, IPAddress)> | |
<cfset validIP = 1> | |
<cfbreak> | |
</cfif> | |
</cfloop> | |
<cfif not validIP> | |
<cfexit> | |
</cfif> | |
</cfif> | |
<cfif len(trim(attributes.variable)) AND isvalid("variableName", attributes.variable)> | |
<cfset caller[attributes.variable] = val(getTickCount() - variables.startTimer)> | |
<cfelseif attributes.type IS "outline"> | |
<cfoutput><fieldset><legend><CFIF LEN(Attributes.Label)>#attributes.label#: </CFIF>#NumberFormat(getTickCount() - variables.startTimer)# ms</legend>#THISTAG.GeneratedContent#</fieldset></cfoutput> | |
<CFSET THISTAG.GeneratedContent = ""> | |
<cfelseif attributes.type IS "inline"> | |
<cfoutput><CFIF LEN(Attributes.Label)>#attributes.label#: </CFIF>#NumberFormat(getTickCount() - variables.startTimer)# ms</cfoutput> | |
<cfelseif attributes.type IS "comment"> | |
<cfoutput><!-- <CFIF LEN(Attributes.Label)>#attributes.label#: </CFIF>#NumberFormat(getTickCount() - variables.startTimer)# ms--></cfoutput> | |
<cfelse> | |
<!--- unknown, just output the content ---> | |
</cfif> | |
</cfif> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment