when HTTP_REQUEST { ## Check if host name match otherwise exit. ## This is needed if you have multiple websites running on same Virtual Server set host1 [string tolower [HTTP::host]] if {$host1 contains "your_website.com"} { ## Set variable #Your website (unique)shortcode, needed to divide multiple online waiting room iRules on same Virtual Server. #In this example the shortcode is SITE1 set OWR SITE1 # Max visitor count # How many concurrent visitors can you serve set max_visitors 10000 # Timeout in seconds # IdleTimeout value is based your cart ideltimeout value. Must at least be equal to your cart IdleTimeout value. # MonitorTimeout is needed for RPM monitoring set IdleTimeout 960 set MonitorTimeout 65 set WaitingRoomTimeout 60 # Decide vistors IP address. Visitors behind a proxy are seen for one visitor. if { ([HTTP::header exists "True-Client-IP"]) and ([HTTP::header "True-Client-IP"] != "") } { set Client_IP [HTTP::header "True-Client-IP"] } else { set Client_IP [IP::client_addr] } # Defining Tables set VisitorsTable VisitorsTable-$OWR-$max_visitors set RPMTable RPMTable-$OWR set WaitingRoomTable WaitingRoom-$OWR-$max_visitors # Generic set unique_id [format "%08d" [expr { int(100000000000 * rand()) }]] set request_uri [HTTP::host][HTTP::uri] set VIP $OWR-vip-url-list # Counters set VisitorCount [table keys -subtable $VisitorsTable -count] set WaitingRoomCount [table keys -subtable $WaitingRoomTable -count] set RPMCount [table keys -subtable $RPMTable -count] set TotalVisitors [expr {$VisitorCount + $WaitingRoomCount}] ## End Variable ## Monitoring # Allow monitoring from internal IP's or subnets. if { ($Client_IP contains "") || ($Client_IP contains "20.20.20") } { # /getcount # If you browse to http://your_website.com/getcount you will see statitics of your Online Waiting Room. # You can use this to integrate with your monitoring system. if { ( [HTTP::uri] equals "/getcount" ) } { HTTP::respond 200 content "\[$TotalVisitors\] \[$max_visitors\] \[$WaitingRoomCount\] \[$RPMCount\]" TCP::close return } } ## End Monitoring ## Register RPM table add -subtable $RPMTable $unique_id $Client_IP\;$request_uri $MonitorTimeout ## Start WaitingRoom # Check if the visitor session still exists set VisitorSession [table lookup -subtable $VisitorsTable $Client_IP] if { $VisitorSession != "" } { # We have a valid session... The lookup has reset the timer on it so just finish processing } else { # No valid session... # Check if VIP URL set vip_url [class match -value [HTTP::uri] contains $VIP] if { not ($vip_url == "") } { # VIP, do nothing } else { # NOT VIP, Check connection count for displaying WR Page # So do we have a free 'slot'? if {$VisitorCount < $max_visitors} { # Yes we have a free slot... Allocate it.. # Register visitor table add -subtable $VisitorsTable $Client_IP $unique_id $IdleTimeout } else { # Max visitors limit reached, show WaitingRoom # Insert visitor into WaitingRoomTable table add -subtable $WaitingRoomTable $Client_IP $unique_id $WaitingRoomTimeout # Show waiting Room HTML HTTP::respond 503 content { Online Waiting Room

Online Waiting Room

We're Sorry

We currently have an exceptionally large number of visitors on the site and you are in the queue.

Please hold tight, it should only be a few minutes. Make sure you stay on this page as you will be automatically redirected.

} TCP::close } } } } }