scache_connect_fast, scache_getindex


resource scache_connect_fast(string id, long index [, string host [, string secret [, long port ]]])
resource scache_pconnect_fast(string id, long index [, string host [, string secret [, long port ]]])
long scache_getindex(resource session)
long $SCacheConnection->getindex()

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


Unique session identifier that distinguishes sessions from each other on scached. Basically this is the cookie or whatever you use to distinguish your users. scache treats this as null terminated c-string even if you provide binary id
Index of the session in backends session table as returned by scache_getindex
Host name of server to connect. If host name begins with slash (/) it is treated as a unix socket path to local filesystem. If hostname is null, system default path or ini-overrided value is used.
Secret to match on already existing session or to be set to a new session. Scache treats this as null terminated c-string meaning it is not binary safe.
Maximum idle time in seconds of created session between queries. If expire time is exceeded, session is invalidated in complete. If expire is false, either system default or it's ini overrided value is used.
TCP-port of host to connect. If port is false, either system default or it's ini overriden value is used.
Something not to be used.

Return values

Session resource on success, FALSE on failure. All other function operate on this returned resource as their first parameter.


Relevance of these functions are questionable unless you run something size of facebook.


Assume we login and initialize session on separate page :

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 :

function get_session_on_other_regular_pages() {
    $cookie = $_COOKIES['MY_SESSION'];
    list($index, $session_id) = explode('/', $cookie);
    return scache_pconnect_fast($session_id, $index);