someone visits website through server A * -> server A creates a new session-id for the visitor and a shared-session-id * -> saves both into database * * later... * * #2 * -> the same device is connected (via loadbalancer) into server B * -> server B don't have the session-id (send by the client) but gets it from db * (is session-id do not exist on the db, then this is a new session) * * = now both server A and B have the same session-id localy * * later... * * #3 * -> some server (let's say B) regenerates the visitors session-id * -> if later the visitor falls into server A, the A will retrieve the new * session id through the #2 scenario * * this way * + any server can update/regenerate the visitor's session-id * + the visitor can be served from both servers randomly * + all session variables exist on the database (always) * + all session variables exist on all servers synced-on-demand * * * stucture of session: * --- * - shared-session-id: (secret + persistent); exposed between servers **primary * - session-id: (may change/regenerate/update); exposed to the client **indexed * - data: serialized array * - creation_timestamp: * - last_touched_timestamp: * - expiration_timestamp: should point to the future or session has expired * - csrf_token: * - JWT_token * - AES-key (this way private data can be kept in browser) * * * what will kept on browser/client (via cookie) * --- * - session-name => session-id * - user info => AES_ectypted(serialized[t=>csfr_token, u=> user_id, s=>SIGNATURE]) * * * Writable file-system shall change * (local writable file-system tree) * --- * /html/storage * | * |-- cache : query-caches * | * `-- session : FS\sessions * | * `-- indexes : share-session-id indexes * * * * NOTE: Session life-cycle * * session_start() * firsts time * --- * ::open(path,PHPSESSID) -> (session_id not exist) -> false * ::create_sid -> '123def' * ::read('123def') ?-or/and- ::close() * * * session_start() * next times * --- * ::open(path, PHPSESSID) -> (session_id exist) -> true * ::read('123def') -> return data -> will fill $_SESSION[*] * * * $_SESSION['foo'] = 'bar'; * --- * ::write('123def', 'foo|s:3:"bar";') -> ['foo' => "bar"] * ::close() * * * session_regenerate_id(); * --- * ::create_sid() -> def123 * * * session_reset() * --- * ::open() * ::read('def123') * * * session_write_close() * --- * ::write('123def', 'foo|s:3:"bar";') * ::close() * * * session_destroy() * --- * ::destroy('def123') * ::close() * */