You can have some code in your application.cfc OnRequestEnd function
to handle something like this.
If you are using a application.CFM, then just create a
OnRequestEnd.cfm template in the root of you application, and this
file will run at the end of every request that is not redirected.
Option #3 is probably the safest bet.
This code snippet will remove the session all together instead of
messing with the session timeouts, which I think in your example is
changing them application wide, which could potentially lead to some
weird behavior between sessions.
<cfloop
list="bot\b,crawl\b,crawler\b,spider\b,\brss,addthis,alexa,bender,custo,doco
mo,esobisubscriber,ezooms,funwebproducts,giganot,google web
preview,heritrix,ia
archiver,ichiro,jeeves,mail.ru,netseer,nutch,powermarks,simple server
monitor,slurp,sogou,twiceler,vse,vortex,websurfer,yahoocachesystem"
index="i" delimiters=",">
<cfif reFind(i, lcase(cgi.http_user_agent))>
<cfset tracker =
createObject("java","coldfusion.runtime.SessionTracker")>
<cfset tracker.getMSessionPool().remove(session.sessionid)>
<cfbreak>
</cfif>
</cfloop>
Alternately you can use a robots.txt if you want to block these bots
all together. This would prevent a CF session from being created.
Believe in CF 10 now there is a sessionInvalidate function which will
do the same thing. Although it doesn't remove jsessions if you are
making use of them. I don't believe the above code snippet will do
that either.
http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WS932f2e4c7c04df8f-23f56e61353e3d07d1-8000.html
Byron Mann
Lead Engineer & Architect
HostMySite.com
On Wed, May 16, 2012 at 11:16 AM, Che Vilnonis <[email protected]> wrote:
>
>
> I maintain a well-trafficked site on CF9 that has occasional memory problems
> that ultimately requires restarts. I am fairly certain the cause of my
> problems is related to "bot" hits and the server's memory they take up. I am
> attempting to set low sessionTimeouts to all bots to remedy this situation.
>
> I've listed a few code samples below I found while researching a solution.
> Is there a "best practice" as to handle this? Any additional code samples
> would be welcome.
>
> Thanks, Che
>
> Method #1
> <cfif structKeyExists(cookie, "CFID")>
> <cfset this.sessionTimeout = createTimeSpan(0,0,10,0)>
> <cfelse>
> <cfset this.sessionTimeout = createTimeSpan(0,0,0,2)>
> </cfif>
>
> Method #3
> <cfif isBoolean(URLSessionFormat("true"))>
> <cfset this.sessionTimeout = createTimeSpan(0,0,10,0)>
> <cfelse>
> <cfset this.sessionTimeout = createTimeSpan(0,0,0,2)>
> </cfif>
>
> Method #3
> <cfset this.sessionTimeout = createTimeSpan(0,0,10,0)>
>
> <cfif len(cgi.http_user_agent) gt 0>
> <cfloop
> list="bot\b,crawl\b,crawler\b,spider\b,\brss,addthis,alexa,bender,custo,doco
> mo,esobisubscriber,ezooms,funwebproducts,giganot,google web
> preview,heritrix,ia
> archiver,ichiro,jeeves,mail.ru,netseer,nutch,powermarks,simple server
> monitor,slurp,sogou,twiceler,vse,vortex,websurfer,yahoocachesystem"
> index="i" delimiters=",">
> <cfif reFind(i, lcase(cgi.http_user_agent))>
> <cfset this.sessionTimeout =
> createTimeSpan(0,0,0,2)>
> <cfbreak>
> </cfif>
> </cfloop>
> <cfelse>
> <cfset this.sessionTimeout = createTimeSpan(0,0,0,2)>
> </cfif>
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:351239
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm