<?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();
 /**
  * @see parent::close()
  */
 function close()
 {
     $this->mutex->release();
     return true;
 }
 /**
  * @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 '';
 }
Esempio n. 4
0
$actor_guid = CValue::get("actor_guid");
$to_treatment = CValue::get("to_treatment", 1);
/** @var CInteropSender $sender */
$sender = CMbObject::loadFromGuid($actor_guid);
$sender->loadRefGroup();
$sender->loadRefsExchangesSources();
$delete_file = $sender->_delete_file;
/** @var CExchangeSource $source */
$source = reset($sender->_ref_exchanges_sources);
if (!$source->active) {
    return;
}
$path = $source->getFullPath($source->_path);
$filename_excludes = "{$path}/mb_excludes.txt";
// Initialisation d'un fichier de verrou de 240 secondes
$lock = new CMbMutex("dispatch-files-{$sender->_guid}");
// On tente de verrouiller
if (!$lock->lock(240)) {
    return;
}
$count = $source->_limit = CAppUI::conf("eai max_files_to_process");
$files = array();
try {
    $files = $source->receive();
} catch (CMbException $e) {
    CCronJobLog::$log = $e->getMessage();
    $e->stepAjax();
}
$fileextension = $source->fileextension;
$fileextension_write_end = $source->fileextension_write_end;
$files_excludes = array();
/**
 * $Id$
 *
 * @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;