Examples

Universal PHP Persistence

A TrafficScript rule can inspect incoming HTTP requests, and select a back-end node based on the request.

The example in Routing by Content Type gives the TrafficScript rule to select a pool based on filename extension. This rule can be modified to pass session persistence data to a chosen Session Persistence Class.

Create a Session Persistence Classes called PHP, and set to use universal session persistence (see Configuring Session Persistence). Next create a TrafficScript rule in the catalog as follows:

$path = http.getPath();

if( string.endsWith( $path, ".php" )) {

 

   # Persist on the PHPSESSID cookie, IP address and

   # user agent

   $phpCookie = http.cookie( "PHPSESSID" ) .

               connection.getRemoteIP() .

               http.getHeader( "User-Agent" );

 

   # Set the persistence key to our unique value

   conection.setPersistenceKey( $phpCookie );

 

   # Select the PHP Session Persistence Class

   connection.setPersistence( "PHP" );

}

Apply this rule to the virtual server handling your traffic. The string passed to the pool.use() function ($phpCookie) is the session persistence data used by the pool.

Requests for files with other extensions (such as .html or .jpg) are ignored by the above rule. These requests are passed on to the other rules used by the virtual server, or to its default Session Persistence Class as set in the default pool.

Also note that only one pool is required, and the Session Persistence is managed entirely by the two separate Session Persistence Classes.