同步可以通过操作系统和数据库本身自己的功能实现,这个和php是没有多大关系.通用的锁倒是没有听说过,除了文件的

解决方案 »

  1.   

    文件的锁也不是完全线程安全的
    手册上这么写的操作系统的锁怎么调用呢
    难道写一个extension?
      

  2.   

    php倒是有一些线程同步函数
    不过只能在unix下用
      

  3.   

    想用shmop做一个内存的缓存类
    内存管理已经有方案了
    就是线程同步不好办
      

  4.   

    怎么建立锁我是知道的
    就是不知道怎么在php当中实现。。
      

  5.   

    问题是你怎么操作内存。
    如设置一块内存共享。在php怎搞
      

  6.   

    共享内存
    Shared memory examples, there are few examples to be found just about anywhere on this subject, I wrote these up a few months ago and am posting them here in case anyone might need these.
    <? 
    //shared memory example.. hope this helps // return a memory hex segment for string.. 
    // limit four chars in  Joel = 0x4a6f656c (joel is my name) 
    function memsegspot($str){ 
            $str = str_pad($str, 4, "Z"); // Z = 5a 
        for ($a=0; $a<4; $a++){ 
          $out1 = substr($str, $a , 1); // walk through 
          $out .= dechex(ord($out1)); // ord returns dec, we need hex for shared memory segments 
        }// 
        return ("0x".$out); // prepend the 
    }//end function // memory location and size of location to alloc 
    function attachtomem($memloc, $alloc){ 
        $sem_id=sem_get($memloc, 1); 
        sem_acquire($sem_id); 
        $shm = shm_attach($memloc, $alloc); 
        return $shm; 
    }// end function   $test = serialize("If you can read this, it is coming out of shared memory.."); 
      $ms = ((strlen($test)+44)*2); 
      $sem_id = sem_get(memsegspot("test"), 1); 
       sem_acquire($sem_id); 
      $smh = shm_attach(memsegspot("test"), $ms); 
      echo "Attached to shm # $smhn"; 
      shm_put_var($smh, $joi{md5($test)}, $test); // $shm_variable is the variable name, $test = the data 
      shm_put_var($smh, $another, serialize("some data")); 
      echo "placed data in shm.n"; 
         
      $out = @shm_get_var($smh, ${md5($test)});   echo unserialize($out) . " n stored as: " . md5($out)."n"; 
      @shm_detach($sem_id); 
      echo "detached from shared memory..n"; 
      echo $ms . " bytes memory used.n"; 
    ?>