/** * Sets an fCache object to store sessions in * * While any type of fCache backend should technically work, it would be * unwise to use the `file` and `directory` types. The `file` caching * backend stores all values in a single file, which would quickly become a * performance bottleneck and could cause data loss with many concurrent * users. The `directory` caching backend would not make sense since it is * the same general functionality as the default session handler, but it * would be slightly slower since it is written in PHP and not C. * * It is recommended to set the `serializer` and `unserializer` `$config` * settings on the fCache object to `string` for the best performance and * minimal storage space. * * For better performance, check out using the built-in session handlers * that are bundled with the following extensions: * * - [http://php.net/memcached.sessions memcached] * - [http://php.net/memcache.examples-overview#example-3596 memcache] * - [https://github.com/nicolasff/phpredis redis] * * The [http://pecl.php.net/package/igbinary igbinary] extension can * provide even more of a performance boost by storing serialized data in * binary format instead of as text. * * @param fCache $backend An fCache object to store session values in * @param string $key_prefix A prefix to add to all session IDs before storing them in the cache * @return void */ public static function setBackend($backend, $key_prefix = '') { if (self::$open || isset($_SESSION)) { throw new fProgrammerException('%1$s must be called before any of %2$s, %3$s, %4$s, %5$s, %6$s, %7$s or %8$s', __CLASS__ . '::setLength()', __CLASS__ . '::add()', __CLASS__ . '::clear()', __CLASS__ . '::enablePersistence()', __CLASS__ . '::get()', __CLASS__ . '::open()', __CLASS__ . '::set()', 'session_start()'); } self::$old_session_module_name = session_module_name(); self::$backend = $backend; self::$key_prefix = $key_prefix; session_set_save_handler(array('fSession', 'openCache'), array('fSession', 'closeCache'), array('fSession', 'readCache'), array('fSession', 'writeCache'), array('fSession', 'destroyCache'), array('fSession', 'gcCache')); // This ensures the session is closed before the fCache object is destructed register_shutdown_function(array('fSession', 'close')); }