/**
  * @see parent::read()
  */
 function read($session_id)
 {
     $ds = self::$ds;
     $this->lock_name = "session_{$session_id}";
     $this->lifetime = ini_get('session.gc_maxlifetime');
     // Init the right mutex type
     $mutex = null;
     switch ($this->mutex_type) {
         case "files":
             $mutex = new CMbFileMutex($this->lock_name);
             break;
         case "system":
             $mutex = new CMbMutex($this->lock_name);
             break;
         default:
             $query = $ds->prepare("SELECT GET_LOCK(%1, %2)", $this->lock_name, $this->lock_timeout);
             $ds->query($query);
             break;
     }
     if ($mutex) {
         $mutex->acquire($this->lock_timeout);
         $this->mutex = $mutex;
     }
     $query = $ds->prepare("SELECT `data`, `expire` FROM `session` WHERE `session_id` = ?1 AND `expire` > ?2;", $session_id, time());
     $result = $ds->exec($query);
     if ($record = $ds->fetchAssoc($result)) {
         $this->expire = $record['expire'];
         $data = $record['data'];
         $new_data = @gzuncompress($data);
         if ($new_data) {
             $data = $new_data;
         }
         $this->data_hash = md5($data);
         return $data;
     }
     $ds->freeResult($result);
     return '';
 }
<?php

/**
 * $Id: httpreq_test_mutex_multi.php 24615 2014-09-01 10:52:44Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage developpement
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 24615 $
 */
CCanDo::checkRead();
$sleep = 5;
$i = CValue::get("i");
$duration = CValue::get("duration", 10);
$colors = array("#f00", "#0f0", "#09f", "#ff0", "#f0f", "#0ff");
// Remove session lock
CSessionHandler::writeClose();
$mutex = new CMbMutex("test", isset($colors[$i]) ? $colors[$i] : null);
$time = $mutex->acquire($duration);
sleep($sleep);
$mutex->release();
$data = array("driver" => get_class($mutex->getDriver()), "i" => $i, "time" => $time);
ob_clean();
echo json_encode($data);
CApp::rip();
 * @package    Mediboard
 * @subpackage developpement
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
$action = CValue::get("action");
$duration = 10;
// Remove session lock
CSessionHandler::writeClose();
CAppUI::stepAjax("test_mutex-try", UI_MSG_OK, $action);
$mutex = new CMbMutex("test");
switch ($action) {
    case "stall":
        CAppUI::stepAjax("test_mutex-acquired", UI_MSG_OK, $mutex->acquire($duration));
        sleep(5);
        $mutex->release();
        break;
    case "die":
        CAppUI::stepAjax("test_mutex-acquired", UI_MSG_OK, $mutex->acquire($duration));
        sleep(5);
        CApp::rip();
        break;
    case "run":
        CAppUI::stepAjax("test_mutex-acquired", UI_MSG_OK, $mutex->acquire($duration));
        $mutex->release();
        break;
    case "lock":
        $locked_aquired = $mutex->lock($duration);
        if ($locked_aquired) {