Need to know how long your ColdFusionMX instance has been up?
Some may have noticed that there is a server.coldfusion.expiration variable (one of many read-only variables in the server scope, within the coldfusion structure). According to the docs, it's supposed to represent the date on which a trial edition of CFMX will expire.
But some have found (and I've confirmed) that on non-trial editions it instead reports the time that the server started. Try it youself:
It'll be a date, but is it in the future? or the past? Assuming it's the past, and you're not running on a trial edition, then it's likely the time your server had started. If you could restart your server and test again, you'll know for sure. :-)
Better formatting of the result
Now, if you want to easily determine how long the server has been up, just use the datediff function to report how many minutes there are between the time reported and the current time:
<cfoutput>#numberformat(uptime)#</cfoutput>
But even better, you could use one of the nifty functions available at the cflib.org that could help present the result minutes in terms of days, hours, and minutes (duration()). Assuming you included the latter in your page, you could then output the value as:
<cfset uptime = duration(server.coldfusion.expiration,now())><br>
<cfoutput>#uptime.days# Day(s) #uptime.hours# Hour(s) #uptime.minutes# Minute(s)
<br>Server started on #dateformat(server.coldfusion.expiration)# at #timeformat(server.coldfusion.expiration)#
</cfoutput>
I may put together a UDF to submit to the cflib to pull all this together, and which also checks if indeed the server being checked is a trial edition, etc. But I'll look forward to hearing people's feedback first.
Other options
Of course, it's worth pointing out that there are of course many tools that will monitor a server's uptime by watching it externally. It may also be possible to ask the operating system to report how long a given process or service has been running. I'll leave that for others to investigate.
Finally, I'll point out that there is indeed a tag in the Adobe Developers Exchange, CF_UpTimeMonger, that purports to help detect server uptime and says it works even for CF 4 and CF5. I have not explored it.



For the benefit of other people thinking of trying this out (of which, I'd imagine there are a fair few):
The duration function isn't m,entioned, so I've coded my own.
function duration(past,present){
this.days=dateDiff("d",past,present);
thenDate=dateAdd("d",this.days,past);
this.hours=dateDiff("h",thenDate,present);
thenDate=dateAdd("h",this.hours,thenDate);
this.minutes=dateDiff("n",thenDate,present);
thenDate=dateAdd("n",this.minutes,thenDate);
this.seconds=dateDiff("s",thenDate,present);
return this;
}
Simple enough.. Not sure it needs any explanaton.
Having clicked the link to it, I noticed that it does a common public domain script thing:
It over complicates the matter in order to make itself seem more complex.
Your examples here suffered from no such thing, don't feel that I'm in any way knocking you. In truth, I thank you for being another rare person determined not to overcomplicate things just to make them seem more complex.
I hate the whole "why use the one line that does the job, instead of using 30 lines to accomplish it, and look cooler" thing - something I've just found myself guilty of in typing this.. So I'll stop now then..
The author's email is offered in the source code as well, so perhaps he might appreciate your observation of a more compact solution and would update it.
Or, note that they (Ray and Rob, who run cflib) always welcome new UDFs there, so you may want to send yours along as an alternative. There are a few variants on a single theme. :-)
And as for typing too many lines in a comment (or blog, or article, or email), you won't hear a complaint from me. I'm one of the most notorious felons on that charge! :-) i just trust that some will appreciate the additional info. To the rest, I lament that they may miss out on little gems here and there as they learn. To each their own, of course. Cheers.
As for submitting "my" version (which I can't claim ownership to really, the foundation of the language, utilities and such weren't mine, they were a hybrid between Allaire, and MM's collective, and much valued input) not much point, those who look at the duration function as listed under CFLIB will more than likely realise that it can be shortened, and do something similar, if not shorter/better/cleaner than my function themselves.
Since my function teaches nothing, I don't feel it worthy of being a public resource.
Indeed, to further extent, I'm very much against the whole "library" thing anyway, I can't stand copy & paste coding,whatever justification may be applied to it, it's still not the developer creatng a solution that fits perfectly the requirements, often something is pasted in which has additional functionality never used
- "Scratch" is a wonderful material, anything can be made from it, when combined with "understandng"
Besides which, I'm one of those people that give something like that 10 second bit of coding without wanting my name attributed to it, hence no website listed, and only my first name.
Please do take this with a hint of alcohol.. There are most likely some major diversions from original points, but I felt compelled to respond to such an agreeable chap as yourself.