coldfusion - application.cfc - conditionally turn on session and/or client management? -


i want reduce overhead of spider/crawler traffic. i'm not expecting catch of it, if can catch 90% of it's win.

what's best way conditionally turn on/off session or client management in application.cfc? i'm thinking along lines of this, i'm not sure if cgi scope defined , initialized when application.cfc instantiated.

this.sessionmanagement = !isspiderrequest(); 

and:

private boolean function isspiderrequest() {      if (refindnocase("googlebot|msnbot|crawler|crawling|spider|wget|curl|baidu|robot|slurp|gigabot|ia_archiver|libwww-perl|lwp-trivial|mediapartners-google", cgi.http_user_agent))         return(true);      return(false); } 

we set session timeout 10 seconds bots. don't errors, don't consume (much) memory.

<!--- set app ---> <cfscript>     this.name = "asdf";     this.applicationtimeout = createtimespan( 0, 0, 60, 0 );     this.setclientcookies = true;     this.datasource = "asdf";     this.sessionmanagement = true;      // test whether user bot     this.isbot = this.checkuseragent();      // visitor bot ~ set fast timeout     if (this.isbot == true) {         //abort;         this.sessiontimeout = createtimespan( 0, 0, 0, 10 );     // visitor not bot ~ set slow timeout     } else {         this.sessiontimeout = createtimespan( 0, 0, 60, 10 );     }  </cfscript>  <cffunction name="checkuseragent">     <cfscript>         // query current list of bot words         local.botwordlist = this.getbotwords();         // visitors current user agent in lower case         local.thisagent = trim(lcase(cgi.http_user_agent));          // @ user agent see if browser          // browser's user agent contains banned word         // return true or false      </cfscript> </cffunction> 

alternative answer... haven't tried this, don't see why won't work.

<!--- set app ---> <cfscript>     this.name = "asdf";     this.applicationtimeout = createtimespan( 0, 0, 60, 0 );     this.datasource = "asdf";     this.setclientcookies = true;      // test whether user bot     this.isbot = this.checkuseragent();      // visitor bot ~ set fast timeout     if (this.isbot == true) {         this.sessionmanagement = false;     // visitor not bot     } else {         this.sessionmanagement = true;         this.sessiontimeout = createtimespan( 0, 0, 60, 10 );     }  </cfscript> 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -