SCache::__construct

Description

SCache::__construct(string id [, string host [, long expire [, bool persistent [, string secret [, long port [, long index ]]]]])

Constructing SCache object prepares and opens socket level connection to scached backend but doesn't query anything. Creating SCache object equals and has same asides as connecting to backend with scache_connect.

Creating object does not initialize session itself. It just prepares connection to operate on already existing session on scached backend. If specified session is new and nonexistent, it must be initialized with SCache::open or SCache::reset before storing or retrieving values.

id is in most cases the cookie or whatever you send to browsers to distinguish them between. secret is meant to be web application specific check to be matched on a case where same scached is used between not so trustworthy apps and servers. If secret is set it must match on further opens. On a simple local-only scacheds secret has no sensible uses.

Parameters

id
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 so it is not binary safe.
host
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.
expire
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.
persistent
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.
secret
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.
port
TCP-port of host to connect. If port is false, either system default or it's ini overriden value is used.
index
Index slot as hint to backend. Using slot indexes is explained on scache_getindex page.

Return values

As a successful result SCache-object is created. Created object has methods documented in class interface.

Object creation might fail on invalid parameters or if backend scached cannot be contacted. If creation fails, SCacheException is thrown.

Examples

<?php
$my_session_identifier = $_COOKIE['MySessionIdentifier'];
try {
    $conn = new SCache($my_session_identifier, 'scached.host.ip');
} catch (SCacheException $e) {
    die('Connection failed');
}
?>