function session_save($session_id, $data) { $data = session_serialize($data); $file_handle = fopen('/var/lib/php/session2/sess_' . $session_id, 'w'); fwrite($file_handle, $data); fclose($file_handle); }
/** * Save a value/object in the global cache. * * @param string $key the key of the value * @param mixed $value the object/string to save * @param int $ttl time to live (in seconds) of the caching * @return bool true if ok, false on error */ function globalcache_set($key, $value, $ttl = false) { if (!hook_already_fired(HOOK_POST_INIT)) { return false; } global $CONFIG; try { switch ($CONFIG['globalcache']['CACHE']) { case globalcache_CACHE_OFF: return true; break; case globalcache_CACHE_APC: return apc_store($GLOBALS["globalcache_key_prefix"] . $key, $value, $ttl); break; case globalcache_CACHE_ZEND: return $GLOBALS["zend_cache_object"]->save($value, globalcache_cleanupkey($GLOBALS["globalcache_key_prefix"] . $key), array(), $ttl); break; case globalcache_CACHE_EACCELERATOR: $ret = eaccelerator_put($GLOBALS["globalcache_key_prefix"] . md5($key), $value, $ttl ? $ttl : 0); return $ret; break; case globalcache_CACHE_MEMCACHE: return $GLOBALS["memcache_object"]->set($GLOBALS["globalcache_key_prefix"] . md5($key), $value, 0, $ttl ? time() + $ttl : 0); break; case globalcache_CACHE_DB: $val = session_serialize($value); $ds = model_datasource($CONFIG['globalcache']['datasource']); try { if ($ttl > 0) { $ds->ExecuteSql("REPLACE INTO wdf_cache(ckey,full_key,cvalue,valid_until)VALUES(?,?,?," . $ds->Driver->Now($ttl) . ")", array(md5($key), $key, $val)); } else { $ds->ExecuteSql("REPLACE INTO wdf_cache(ckey,full_key,cvalue)VALUES(?,?,?)", array(md5($key), $key, $val)); } } catch (Exception $ex) { $ds->ExecuteSql("CREATE TABLE IF NOT EXISTS wdf_cache (\n ckey VARCHAR(32) NOT NULL,\n cvalue TEXT NOT NULL,\n valid_until DATETIME NULL,\n\t\t\t\t\t\tfull_key TEXT NOT NULL,\n PRIMARY KEY (ckey))"); if ($ttl > 0) { $ds->ExecuteSql("REPLACE INTO wdf_cache(ckey,full_key,cvalue,valid_until)VALUES(?,?,?," . $ds->Driver->Now($ttl) . ")", array(md5($key), $key, $val)); } else { $ds->ExecuteSql("REPLACE INTO wdf_cache(ckey,full_key,cvalue)VALUES(?,?,?)", array(md5($key), $key, $val)); } } return true; break; } } catch (Exception $ex) { WdfException::Log($ex); die($ex->__toString()); } return false; }
/** * Stores a string value into the internal cache. * * Noting to say. Just stores where you want. * @param string $key a key for the value * @param string $value the value to store * @param int $ttl Time to life in seconds. -1 if it shall live forever * @param bool $use_global_cache If true stores in the global cache (see globalcache module) * @param bool $use_session_cache If true stores in the SESSION cache * @return void */ function cache_set($key, $value, $ttl = false, $use_global_cache = true, $use_session_cache = true) { global $CONFIG; if ($ttl === false) { $ttl = $CONFIG['system']['cache_ttl']; } if ($use_global_cache && system_is_module_loaded('globalcache')) { globalcache_set($key, $value, $ttl); } if ($use_session_cache) { $_SESSION["system_internal_cache"][$key] = session_serialize($value); } }