Pete Freitag Pete Freitag

How Long Has Your ColdFusion Server Been Running?

Updated on October 24, 2022
By Pete Freitag

Someone asked on the CFML slack recently how can you find out how long your ColdFusion (or Lucee) server has been running via code.

How long has the server been running?

createObject("java", "").getRuntimeMXBean().getUptime()

This approach uses Java's Management Factory Runtime Bean to get the number of milliseconds since the server started.

What date / time did the server start?

The Runtime Bean in Java, also has a getStartTime() function that returns the time the jvm was started as a timestamp.

start_time = createObject("java", "").getRuntimeMXBean().getStartTime();
java_date = createObject("java", "java.util.Date").init(start_time);
writeOutput(dateTimeFormat(java_date, "long"));

Here's a trycf snippet for both examples.

Finally someone pointed out that on licensed ColdFusion server you can actually use the variable coldfusion.server.expiration to get the time that the server started. Charlie Arehart has a blog entry all about that approach. The blog entry was from 2006, but it apparently still works! That approach might not work in all cases or on Lucee however, but it really simpler than the approach I have here.

coldfusion lucee

How Long Has Your ColdFusion Server Been Running? was first published on October 24, 2022.

If you like reading about coldfusion, or lucee then you might also like:

FuseGuard Web App Firewall for ColdFusion

The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.

The weekly newsletter for the CFML Community

Post a Comment