Greg's Blog

helping me remember what I figure out

How to Clear Application/session Variables Without Re-booting Your Server

| Comments

I am sure you have come across this problem, you make some changes to a page or are debugging a page, only to find that your session and application variables are set and viewing the changes or detecting the problem is now impossible. The first option for clearing these variables was to stop and restart your cold fusion application service. Under NT you would type the following command from the command line:

net stop “cold fusion application server”
The Cold Fusion Application Server service is stopping..
The Cold Fusion Application Server service was stopped successfully.


net start “cold fusion application server”
The Cold Fusion Application Server service is starting…
The Cold Fusion Application Server service was started successfully.

This would indeed clear your variables but is a bit cumbersome and down right useless if you don’t have access to the server. So what do you do then? Well the answer I found in the CF in the Certified CF Developer Study Guide (See reading is useful… and it’s a pretty useful book too). All session and application variables are stored in a structure and with the help of the StructClear() function you are now able to clear these. To facilitate this step I created a new Cold Fusion template, added the following lines and saved it as clear_session.cfm

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>

<html>
<head>
<title>Clear session variables</title>
</head>

<body>

<cfscript>
StructClear(session);
StructClear(application);
</cfscript>

</body>
</html>

So there you go, just run this page and your session and application variables will be cleared (please note that if you require to log on to your site and run this page you will clear you session variable for that too and hence be required to log back in again). I’ll be writing about how to view the content of these structures in the near future.