How Long Has Your ColdFusion Server Been Running?
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", "java.lang.management.ManagementFactory").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", "java.lang.management.ManagementFactory").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.
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:
- OpenSSL and ColdFusion / Lucee / Tomcat
- Simple Parallel Execution in ColdFusion or Lucee
- Spring4Shell and ColdFusion
- Log4j CVE-2021-44228 Log4Shell Vulnerability on ColdFusion / Lucee
The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.