Skip to content

Instantly share code, notes, and snippets.

@Danack
Created November 17, 2013 17:58
Show Gist options
  • Save Danack/7516111 to your computer and use it in GitHub Desktop.
Save Danack/7516111 to your computer and use it in GitHub Desktop.
Example of session behaviour. Default PHP locks the session object so that only one process can modify it at once, i.e. the numbers in the two frames will always be different. In APCu PS they can be duplicated.
<?php
session_start();
echo "This is frame 1 with ".ini_get("session.save_handler")." handler <br/>";
if (isset($_SESSION['foo']) == false) {
sleep(2);
$_SESSION['foo'] = 0;
}
for($x=0; $x<10 ; $x++) {
$_SESSION['foo'] += 1;
echo "Foo is ".$_SESSION['foo']."<br/>";
usleep(100000);
}
<?php
session_start();
echo "This is frame 2 with ".ini_get("session.save_handler")." handler <br/>";
if (isset($_SESSION['foo']) == false) {
sleep(2);
$_SESSION['foo'] = 0;
}
for($x=0; $x<10 ; $x++) {
$_SESSION['foo'] += 1;
echo "Foo is ".$_SESSION['foo']."<br/>";
usleep(100000);
}
<html>
<body>
<iframe src='frame1.php' width='200px' height='400px'></iframe>
<iframe src='frame2.php' width='200px' height='400px' ></iframe>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment