- static function load_data($id, $sess)
- {
- log_main("load_data: id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
-
- do {
- if (($tok = @ftok(FTOK_PATH."/user".$id, "C")) == -1) {
- log_main("ftok failed");
- break;
- }
-
- if (($shm_sz = sharedmem_sz($tok)) == -1) {
- log_main("shmop_open failed");
- }
-
- if ($shm_sz == -1)
- $shm_sz = SHM_DIMS_U_MIN;
-
- if ($shm = shm_attach($tok, $shm_sz)) {
- if (($user = @shm_get_var($shm, $tok)) == FALSE) {
- break;
- }
- if ($sess != FALSE && $user->sess != $sess) {
- break;
- }
- log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE"));
-
- if ($user == FALSE) {
- log_only("INIT MAIN DATA");
-
- // SHSPLIT FIXME: init_data for User class ??
- $user = self::create($id, "", "");
- if (@shm_put_var($shm, $tok, $user) == FALSE) {
- log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
- log_only(serialize($user));
- }
- log_shme("User::save_data2");
- }
- else {
- if ($sess != FALSE) {
- /*
- * NOTE: this part is for check only, theoretically
- * user->step anch proxy_step are set allways at the same value
- */
- $old_step = $user->step;
- $arr = self::load_step($sess);
- $user->step = $arr['s'];
- if ($old_step != $user->step) {
- log_crit("steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
- }
- }
- }
- $user->shm_sz = $shm_sz;
-
- shm_detach($shm);
- }
-
- //
- // SHSPLIT: load users from the shared memory
- //
- return ($user);
- } while (0);
-
- return (FALSE);
- }
-
-
- static function save_data($user, $id)
- {
- GLOBAL $sess;
-
- $shm = FALSE;
-
- if (($tok = @ftok(FTOK_PATH."/user".$id, "C")) == -1) {
- return (FALSE);
- }
- while ($user->shm_sz < SHM_DIMS_U_MAX) {
- if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE)
- break;
-
- // log_only("PUT_VAR DI ".strlen(serialize($user)));
- if (@shm_put_var($shm, $tok, $user) != FALSE) {
- shm_detach($shm);
- if ($user->sess != "")
- $user->save_step();
-
- log_shme("User::save_data");
-
- log_main("User[".$id."] saved.");
- return (TRUE);
- }
- if (shm_remove($shm) === FALSE) {
- log_only("REMOVE FALLITA");
- break;
- }
- shm_detach($shm);
- $user->shm_sz += SHM_DIMS_U_DLT;
- }
-
- if ($shm)
- shm_detach($shm);
-
- return (FALSE);
- }
-