The _CF_NODEBUG Parameter

Most people know that enabling request debugging output via the ColdFusion administrator has some overhead. If you are running a CFC heavy application the performance hit can be quite noticeable. To get around the performance issues you may be tempted to use <cfsetting> with the showdebuoutput attribute set to false. While this does indeed suppress the debugging output, it does not disable the debugging service or alleviate the performance issues you may see with debugging. You can confirm this using the following template:

<cfparam name="form.showdebugoutput" type="boolean" default="YES">
<cfsetting showdebugoutput="#form.showdebugoutput#">

<cfset showdebugoutput = NOT form.showdebugoutput />

<html>
<head>
<title>Debugging Tests</title>
</head>
<body>
<h1>Debugging Tests</h1>

<cfoutput>Show Debug Output: #form.showdebugoutput#</cfoutput><br/>
<cfoutput>IsDebugMode(): #IsDebugMode()#</cfoutput><br/>

<cfset factory = CreateObject("java","coldfusion.server.ServiceFactory")>
<cfset cfdebugger = factory.getDebuggingService().getDebugger()>
<cfoutput>Debugger running: #IsDefined("cfdebugger")#</cfoutput><br/>

<cfoutput>
<form method="POST">
<fieldset>
<legend>CFSETTING SHOWDEBUGOUTPUT #showdebugoutput#</legend>
<input type="hidden" name="showdebugoutput" value="#showdebugoutput#">
<input type="submit">
</fieldset>
</form>
</cfoutput>

</body>
</html>

If you run the above template on a site with classic debugging enabled you should see something like the following:

If you submit the form on this test template to set <cfsetting showdebugoutput="false"/> you will see that you can still get the ColdFusion debugger via the ServiceFactory:

You can confirm the debugging service is still collecting data by placing a blank Application.cfm and the following OnRequestEnd.cfm template in the same directory as your test template:

<cfset factory = CreateObject("java","coldfusion.server.ServiceFactory")>
<cfset cfdebugger = factory.getDebuggingService().getDebugger()>
<cfif IsDefined("cfdebugger")>
<cfset data = cfdebugger.getData() />
<cfdump var="#data#" />
</cfif>

So, while you can't truly disable the debugging service with <cfsetting>, there is another option: _cf_nodebug. The built in ColdFusion AJAX libraries append the _cf_nodebug parameter to AJAX requests via a URL parameter so that the standard ColdFusion debugging output does not interfere with XML or JSON results. The interesting thing about this parameter is that it not only disables the debugging output, it completely disables the debugging service. Here is another to test template I used to confirm this behavior:

<cfparam name="form.cfsetting" type="boolean" default="false">

<cfif form.cfsetting>
<cfsetting showdebugoutput="false">
</cfif>

<html>
<head>
<title>Debugging Tests</title>
</head>
<body>
<h1>Debugging Tests</h1>

<cfoutput>IsDebugMode(): #IsDebugMode()#</cfoutput><br/>

<cfset factory = CreateObject("java","coldfusion.server.ServiceFactory")>
<cfset cfdebugger = factory.getDebuggingService().getDebugger()>
<cfoutput>Debugger running: #IsDefined("cfdebugger")#</cfoutput><br/>

<form action="index.cfm" method="POST">
<fieldset>
<legend>CFSETTING SHOWDEBUGOUTPUT FALSE</legend>
<input type="hidden" name="cfsetting" value="true">
<input type="submit">
</fieldset>
</form>

<form action="index.cfm?_cf_nodebug=true" method="POST">
<fieldset>
<legend>_cf_nodebug URL PARAM TRUE</legend>
<input type="submit">
</fieldset>
</form>

<form action="index.cfm" method="POST">
<fieldset>
<legend>_cf_nodebug FORM FIELD TRUE</legend>
<input type="hidden" name="_cf_nodebug" value="true">
<input type="submit">
</fieldset>
</form>

<form action="index.cfm?_cf_nodebug=true" method="POST">
<fieldset>
<legend>_cf_nodebug FORM FIELD FALSE AND URL PARAM TRUE</legend>
<input type="hidden" name="_cf_nodebug" value="false">
<input type="submit">
</fieldset>
</form>

<form action="index.cfm?_cf_nodebug=false" method="POST">
<fieldset>
<legend>_cf_nodebug FORM FIELD TRUE AND URL PARAM FALSE</legend>
<input type="hidden" name="_cf_nodebug" value="true">
<input type="submit">
</fieldset>
</form>

</body>
</html>

This test template reveals a few interesting things about _cf_nodebug behavior. First, you can disable debugging using either a FORM or URL parameter, with the URL parameter given preference if both are defined. Second, even though the debugging service is completely disabled IsDebugMode() still returns true, which is something to watch out for if you happen to use that function.

In conclusion, if you need to disable debugging for a single request, say for application start up, you can append _cf_nodebug=true to the URL and avoid the ColdFusion debugging overhead.

Related Blog Entries

Comments
achebe's Gravatar Thanks! This is great stuff, I've been looking for a solution to this problem for a while now.
# Posted By achebe | 4/2/09 12:50 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.