scache_connect_fast, scache_getindex
Description
scache_*_fast functions are equal to theirs non-fast versions, but offer extra parameter to pass a "hint" to backend for supposed location of session in backends session table. Fast functions might offer some performance improvement with very large session tables.
Scached backend tries first the session at location suggested by index and if it fails or appears to be wrong one it does a full search from it's session tree as like the non-fast equivalents do. It is perfectly legal to pass an invalid index if valid is currently not known. Index is just a hint.
Index to be passed is resolved by scache_getindex. Procedure is explained in example code below.
There is no class interface equivalent for scache_*connect*-functions. Index and flag for persistent connection is set on SCache object's constructor
Parameters
Return values
Session resource on success, FALSE on failure. All other function operate on this returned resource as their first parameter.
Notes
Relevance of these functions are questionable unless you run something size of facebook.
Examples
Assume we login and initialize session on separate page :
<?php /* function the_login_on_login_page($user, $pass) { if (is_valid_login($user, $pass)) { /* initialize session */ $session_id = md5sum(uniqid() . uniqid()); $session = scache_preset($session_id); $index = scache_getindex($session); /* encode index to session identifier */ $cookie = $index . '/' . $session_id; header("Cookie: MY_SESSION=$cookie"); } }
And on subsequent pages we just connect :
<?php function get_session_on_other_regular_pages() { $cookie = $_COOKIES['MY_SESSION']; list($index, $session_id) = explode('/', $cookie); return scache_pconnect_fast($session_id, $index); } ?>