2

just moved to AWS and launched 2 RHEL Servers, load-balanced. And installed Apache and PHP. Thats all. And second is even the image of first server.

But suddenly i just noticed the PHP $_SESSION variables are NOT IN SYNCED. Having differently on each.

After i run this:

<?php
session_start();

if ( $_GET["setvalue"] ) {
    $_SESSION["sess_test"] = $_GET["setvalue"];
}

echo "session value: ".$_SESSION["sess_test"];
?>

Then i assign like:

After i assign the Session Value, and refresh again and again (ofcourse by removing the "?setvalue=hello" portion), the same page is showing 2x different values (as i have two load balanced servers) whenever i refresh.

One is showing:

  • session value: hello

And next time is showing:

  • session value:

After i give the different value again, only one hitting server is showing the last value and other server is still not get updated with the last value.

ANY IDEA PLEASE? :(

夏期劇場
  • 17,821
  • 44
  • 135
  • 217

1 Answers1

3

If you are using the default file-based session storage engine, then naturally, you can't load balance them (at least, not without using some kind of stickiness).

What you need is centralized storage for sessions, e.g. using a database or memcache.

See also PHP sessions in a load balancing cluster - how?

Community
  • 1
  • 1
Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
  • Huh :S i even don't know. I just moved to AWS and launched 2 RHEL Servers. And installed Apache and PHP. Thats all. And second is even the image of first server :( – 夏期劇場 Jul 26 '13 at 10:49