{
$this->step = $step & 0x7fffffff;
- do {
- if (validate_sess($this->sess) == FALSE)
- break;
- if (file_exists(BIN5_PROXY_PATH) == FALSE)
- mkdir(BIN5_PROXY_PATH, 0775, TRUE);
- if (($fp = @fopen(BIN5_PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
- break;
- fwrite($fp, pack("LL",$this->step, $this->idx));
- fclose($fp);
-
- log_main("step_set [".$this->sess. "] [".$this->step."]");
-
- return (TRUE);
- } while (0);
-
- return (FALSE);
+ return TRUE;
}
function step_inc($delta = 1) {
/* modularization because unpack() not manage unsigned 32bit int correctly */
$this->step &= 0x7fffffff;
- if (validate_sess($this->sess)) {
- if (file_exists(BIN5_PROXY_PATH) == FALSE)
- mkdir(BIN5_PROXY_PATH);
- $fp = fopen(BIN5_PROXY_PATH."/".$this->sess.".step", 'w');
- fwrite($fp, pack("LL", $this->step, $this->idx));
- fclose($fp);
-
- log_main("step_inc [".$this->sess. "] [".$this->step."]");
-
- return (TRUE);
- }
-
- return (FALSE);
+ return (TRUE);
}
-
- static function step_get($sess)
+
+ static function load_step($sess)
{
$fp = FALSE;
do {
break;
if (($s = fread($fp, 8)) == FALSE)
break;
- if (strlen($s) != 8)
+ if (mb_strlen($s, "ASCII") != 8)
break;
$arr = unpack('Ls/Li', $s);
fclose($fp);
return (FALSE);
}
+
+ function save_step()
+ {
+ do {
+ if (validate_sess($this->sess) == FALSE)
+ break;
+ if (file_exists(BIN5_PROXY_PATH) == FALSE)
+ mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+ if (($fp = @fopen(BIN5_PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
+ break;
+ fwrite($fp, pack("LL",$this->step, $this->idx));
+ fclose($fp);
+
+ log_main("step_set [".$this->sess. "] [".$this->step."]");
+
+ return (TRUE);
+ } while (0);
+
+ return (FALSE);
+ }
+
static function load_data($tab_id, $id, $sess)
{
log_only(serialize($user));
}
}
+ else {
+ if ($sess != FALSE) {
+ // This part isn't strictly required but is good to verify
+ // the coerence of cached and User class saved value of step field.
+ $old_step = $user->step;
+ $arr = Bin5_user::load_step($sess);
+ $user->step = $arr['s'];
+ if ($old_step != $user->step) {
+ log_crit("Bin5:: steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
+ }
+
+ }
+ }
$user->shm_sz = $shm_sz;
// log_only("PUT_VAR DI ".strlen(serialize($user)));
if (shm_put_var($shm, $tok, $user) != FALSE) {
shm_detach($shm);
+ $user->save_step();
log_main("User[".$id."] saved.");
return (TRUE);
}
class Bin5 {
+ static $delta_t = array();
+
var $user;
var $table;
var $comm; // commands for many people
{
GLOBAL $sess;
- log_lock("LOCK_DATA ".FTOK_PATH."/bin5/table".$table_idx."/table");
+ log_main("lockinfo: DATA ".FTOK_PATH."/bin5/table".$table_idx."/table");
// echo "LOCK: ".FTOK_PATH."/main";
// exit;
// WARNING monitor this step
return (FALSE);
}
if (sem_acquire($res)) {
- log_lock("LOCK table ".$table_idx."[res: ".$res."]");
- return ($res);
+ self::$delta_t[$table_idx] = microtime(TRUE);
+ log_lock("LOCK table [".$table_idx."] [".self::$delta_t[$table_idx]."]");
+
+ return (new Vect(array('res' => $res, 'tab' => $table_idx)));
}
else {
- log_lock("LOCK table ".$table_idx.":FAILED");
- return (FALSE);
+ log_lock("LOCK table ".$table_idx.":FAILED");
+ return (FALSE);
}
}
- function unlock_data($res)
+ function unlock_data($res_vect)
{
GLOBAL $sess;
-
- log_lock("UNLOCK table [res: ".$res."]");
+
+ $res = $res_vect->getbyid('res');
+ $tab = $res_vect->getbyid('tab');
+
+ log_lock("UNLOCK table [".$tab."] [".(microtime(TRUE) - (self::$delta_t[$tab]))."]");
return (sem_release($res));
}
break;
if (($s = fread($fp, 4)) == FALSE)
break;
- if (strlen($s) != 4)
+ if (mb_strlen($s, "ASCII") != 4)
break;
$arr = unpack('Le', $s);
if ($arr['e'] > $tm)