Re: cookie-less sessions

From: Baptiste <bedis9#gmail.com>
Date: Sat, 6 Aug 2011 11:27:53 +0200


I made it work on our Aloha load-balancer (4.1.2) :)

PHP code on the server:

cookie.php :
<?php
session_start();
header("Location: /?ID=" . session_id());

echo apache_getenv("SERVER_ADDR");
?>

test script.php:
<?php
echo apache_getenv("SERVER_ADDR");
?>

it creates a set-cookie with cookie name PHPSESSID and redirect the use with a URL param ID (which has the same value as the cookie id).

HAProxy configuration, on my backend configuration:   stick-table type string len 32 size 10K   stick store-response set-cookie(PHPSESSID)   stick on url_param(ID)

The test:
First request:

$ curl -D - http://aloha/cookie.php
HTTP/1.1 302 Found
Date: Sat, 06 Aug 2011 09:13:45 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze3
Set-Cookie: PHPSESSID=8a28f7089e9d70c3375505c9620472db; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache
Location: /?ID=8a28f7089e9d70c3375505c9620472db Vary: Accept-Encoding
Content-Length: 68
Content-Type: text/html

192.168.10.101

Second request, with the ID on URL:

$ curl -D - http://aloha/script.php?ID=8a28f7089e9d70c3375505c9620472db HTTP/1.1 200 OK
Date: Sat, 06 Aug 2011 09:15:21 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze3
Vary: Accept-Encoding
Content-Length: 17
Content-Type: text/html

192.168.10.101

Note that I'm using the same backend, since the IP printed is the same.

Let's have a look at the table now:

echo "show table bk_myappli" | socat unix-connect:/var/run/haproxy.stat stdio # table: bk_myappli, type: string, size:10240, used:5 0x14b5694: key=8a28f7089e9d70c3375505c9620472db use=0 exp=0 server_id=1

Hank, as said before, it's not yet in HAProxy. I can't speak on behalf of Willy, but you can ask him to kindly include it on the next 1.5-dev release :)

cheers Received on 2011/08/06 11:27

This archive was generated by hypermail 2.2.0 : 2011/08/06 11:30 CEST