Originally posted by devinemke
if you only want 1 session at a time then simply check the contents of your session.save_path directory. if there is already a session there then echo an error. for this to work properly you would need to write your own session flushing routine to get rid of expired session files.
Yes thats what I'd initially thought. but garbage collection accuracy asked me to look elsewhere. a zend automated process maybe. but again alas! 🙁
anyhow heres how I've implemented this....
if($handle = opendir('/tmp/myapp'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && substr($file,0,5) == "sess_")
{
session_start();
if($file == "sess_".session_id())
{
// Access Permitted! :)
}
else
{
// LOCKED!!
session_destroy();
echo "<html><body><br>";
echo "<center><table><tr><th>Access Denied!</th></tr>";
echo "<tr><td>One process of MyApp is already running. Please try again after 5 minutes.</td></tr>";
echo "</table></center>";
echo "</body></html>";
closedir($handle);die;
}
}
else
{
session_start();
}
}
closedir($handle);
}
With the following php.in vars -
session.gc_probability = 100 (this is a MUST)
session.gc_maxlifetime = 300 (5 mins)
session.cookie_lifetime = 300
session.cache_expire = 5 ( mins just to make sure) 😉
This gives user2 a latency period of max 5 mins before he can open the page from another comp (provided no activitiy has been done by user1)
Thanks for the valid suggestion bud!!