Determine How Long Your ColdFusion Page Has Been Running Using GetPageContext()

Posted April 26, 2007 at 8:13 AM

Tags: ColdFusion

The other day, I discovered how to get the date/time at which your ColdFusion page started running. Before I had found this, I had contemplated using a GetTickCount() at the beginning of my page run to mark this time. But, this method is ganky and requires updates to more than one file. By reaching into the Page Context, I am able to grab the start date/time value of the page without having to modify any other templates:

 Launch code in new window » Download code as text file »

  • <!---
  • Use the page and fusion context objects to get the
  • date/time stamp at which this page started processing.
  • Then, get the number of seconds that that start date is
  • smaller than the current date/time stamp value.
  • --->
  • <cfset intRunTimeInSeconds = DateDiff(
  • "s",
  • GetPageContext().GetFusionContext().GetStartTime(),
  • Now()
  • ) />
  •  
  •  
  • <!---
  • Output the number of seconds in which the page has
  • been processing.
  • --->
  • <p>
  • Page has been processing for:
  • #intRunTimeInSeconds# Seconds
  • </p>

Running the above, I get the output:

Page has been processing for: 0 Seconds

Zero seconds; not surprising considering the page has what amounts to like three lines of code on it. While this might seem completely insignificant, this is a very cool thing to know. I will go into that a bit more next.

Download Code Snippet ZIP File

Comments (7)  |  Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




Keep your Web site content fresh and your overhead costs low with Savvy Content Manager

Reader Comments

You should consider filing a request for this to be added to the language (I mean a shortcuz function). I can see it being useful.

Posted by Raymond Camden on Apr 26, 2007 at 4:50 PM


Yeah, if we have GetTickCount(), maybe something like GetElapsedTickCount() or GetPageTickCount() would be very nice.

Posted by Ben Nadel on Apr 26, 2007 at 5:41 PM


Hi Ben,

Any idea why i get this error?

"The selected method getFusionContext was not found. Either there are no methods with the specified method name and argument types, or the method getFusionContext is overloaded with arguments types that ColdFusion can't decipher reliably. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity. "

I tried javacast and still same error occurs.

Posted by truthseeker on Dec 6, 2007 at 4:14 AM


@truthseeker,

That is odd because the function GetFusionContext() doesn't take any methods. What version of ColdFusion are you running?

Posted by Ben Nadel on Dec 6, 2007 at 7:13 AM


@Ben,

I'm using 6.1. Hmm... Could this be a version issue? Haven't tested it in later versions, though. 'Coz the development is still running in 6.1.

Posted by truthseeker on Dec 6, 2007 at 8:50 PM


@truthseeker,

To be honest, I wouldn't even know what to tell you. It is possible that the underlying mechanisms behind GetPageContext() changed going into MX7 (what we use in production).

Posted by Ben Nadel on Dec 7, 2007 at 7:15 AM


guess i'll just have to stick with GetTickCount() for now :)

Posted by truthseeker on Dec 7, 2007 at 8:42 AM


Post Comment  |  Ask Ben


Home   |   Web Log   |   ColdFusion   |   Projects   |   Resume   |   Job Form   |   Search   |   Contact
Epicenter Consulting - Custom Software Solutions for Business Evolution HostMySite.com - The Leader In ColdFusion Hosting