本文整理汇总了PHP中Lock类的典型用法代码示例。如果您正苦于以下问题:PHP Lock类的具体用法?PHP Lock怎么用?PHP Lock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: perform
/**
* Perform an update.
*
* If enabled (default) this method will send a E_USER_NOTICE about the update.
*
* @see setNotice()
*/
public function perform(DataBackend $backend)
{
$isNotice = $this->notice;
$lock = new Lock(self::UPDATE_LOCK);
$lock->nonblockingExecuteOnce(function () use($backend, $isNotice) {
$backend->update();
if ($isNotice) {
trigger_error("bav's bank data was updated sucessfully.", E_USER_NOTICE);
}
});
}
示例2: getLockForm
/**
* gets lightbulb form
* @return string HTML div
*/
public static function getLockForm()
{
//get all lightbulbs from db and create button for each
$lockArray = self::get_appliances_by_type('lock');
$form = "<div><h2>Locks</h2>";
foreach ($lockArray as $lockItem) {
$lock = new Lock($lockItem['applianceId']);
$onclick = "toggleLock(this); ";
$button = $lock->getButtonDiv($onclick);
$form .= "<div>{$button}</div>";
}
$form .= "</div>";
return $form;
}
示例3: buildDataBackend
/**
* Builds a configured data backend.
*
* If configured this method would automatically install the backend. I.e. a first
* call will take some amount of time.
*
* @return DataBackend
* @throws DataBackendException
*/
private function buildDataBackend()
{
$configuration = ConfigurationRegistry::getConfiguration();
$backend = $this->makeDataBackend();
// Installation
if ($configuration->isAutomaticInstallation() && !$backend->isInstalled()) {
$lock = new Lock(self::INSTALL_LOCK);
$lock->executeOnce(function () use($backend) {
$backend->install();
});
}
// Update hook
register_shutdown_function(array($this, "applyUpdatePlan"), $backend);
return $backend;
}
示例4: processControlMenu
public function processControlMenu()
{
if (isset($_REQUEST['main_tab'])) {
$option = $_REQUEST['main_tab'];
if ($option === 'lights') {
echo Lightbulb::getLightBulbForm();
} elseif ($option === 'locks') {
echo Lock::getLockForm();
} elseif ($option === 'thermostat') {
echo Thermostat::getThermostatForm();
} else {
if ($option == 'lightGroups') {
echo LightGroup::getLightGroupForm();
} else {
echo "<h3>Undefined Tab Selected</h3>";
}
}
//continue with locks
//thermostat etc.
$this->display = FALSE;
} else {
$command = escapeshellcmd("python /var/www/python/killall.py");
shell_exec($command);
$command = escapeshellcmd("python /var/www/python/clear.py");
shell_exec($command);
}
}
示例5: __call
function __call($fnName, $args)
{
if (in_array($fnName, self::$functionExceptions)) {
return call_user_func_array(array($this, $fnName), $args);
}
//get node (since all private functions require it)
$node = $args[0] = $this->getNode($args[0]);
if ($this->fkColumn) {
$this->baseWhere[$this->fkColumn] = $node[$this->fkColumn];
}
//get foreign key to localise lock
$lockName = 'DbTree-' . $this->table;
if ($this->fkColumn) {
$lockName .= '-' . $node[$this->fkColumn];
}
$this->__methodExists($fnName);
Lock::req($lockName, 2);
$this->db->db->beginTransaction();
try {
$return = call_user_func_array(array($this, $fnName), $args);
$this->db->db->commit();
} catch (Exception $e) {
Lock::off($lockName);
$this->db->db->rollBack();
throw $e;
}
Lock::off($lockName);
return $return;
}
示例6: read
public function read()
{
$this->_open('r');
$lock = new Lock($this);
$lock->sh();
if ($this->ttl > 0) {
if (time() - filemtime($this->fileName) >= $this->ttl) {
$lock->unlock();
$this->_close();
unlink($this->fileName);
return false;
}
}
$content = false;
while (!feof($this->handle)) {
$content .= fread($this->handle, 4012);
}
$lock->unlock();
$this->_close();
return $content;
}
示例7: check_data
/**
* 监测是否过期 删除对用过期信息
*/
public function check_data()
{
$result = Lock::all()->toArray();
if (!empty($result)) {
$nowtime = time();
foreach ($result as $key => $value) {
if ($value['time'] <= $nowtime) {
$this->del_data[$value['contentid']];
}
}
}
}
示例8: fetchRecord
public function fetchRecord()
{
try {
$lock = Lock::acquire('getPendingRecord');
if (($r = $this->getPendingRecord()) == NULL) {
throw new fExpectedException('No pending record.');
}
$p = $r->getProblem();
$r->setJudgeStatus(JudgeStatus::WAITING);
$r->store();
Lock::release($lock);
echo json_encode(array('id' => $r->getId(), 'problem_id' => $p->getId(), 'code_language' => $r->getLanguageName(), 'code' => base64_encode($r->getSubmitCode()), 'memoryLimit' => $p->getMemoryLimit(), 'timeLimit' => $p->getTimeLimit(), 'caseScore' => $p->getCaseScore(), 'caseCount' => $p->getCaseCount(), 'Timestamp' => $p->getLastModified()), JSON_NUMERIC_CHECK);
} catch (fException $e) {
echo -1;
}
}
示例9: release_lock
public static function release_lock($UID, $entity_type, $user)
{
// add record to lock table in order to specify that the kbit is no longer locked
// NOTE: it is recomended to implement the lock in separated class
if (Lock::is_locked($UID, $entity_type) == false) {
debugLog::log("<i>[Lock::release_lock]:</i> cannot release lock of [" . $entity_type . "]: " . $UID . " because it is not locked");
return false;
}
if (Lock::is_locked_by_user($UID, $entity_type, $user) == false) {
debugLog::log("<i>[Lock::release_lock]:</i>cannot release lock of [" . $entity_type . "]: " . $UID . " because it is not locked by the same user");
return false;
}
$dbObj = new dbAPI();
// disable lock records
$query = "UPDATE CONTENT_LOCK SET ENABLED = 0 WHERE LOCKED_UID = '" . $UID . "' AND ENTITY_TYPE = '" . $entity_type . "' AND LOCK_STATUS = 'LOCKED' AND ENABLED = 1 ";
$results = $dbObj->run_query($dbObj->db_get_contentDB(), $query);
if ($results == false) {
debugLog::log("<i>[Lock::release_lock]:</i>cannot release lock of [" . $entity_type . "]: " . $UID . " because of database update error");
return false;
}
// add release record
$query = "INSERT INTO CONTENT_LOCK (LOCKED_UID, ENTITY_TYPE, ENABLED, LOCK_STATUS, USER_ID, CREATION_DATE) VALUES (" . $UID . ", '" . $entity_type . "', 1, 'UNLOCKED', " . $user . ",'" . date("Y-m-d H:i:s") . "')";
return $dbObj->run_query($dbObj->db_get_contentDB(), $query) == true;
}
示例10: sleep
<?php
require "Lock.php";
$lock = Lock::factory("Dreadlock");
print "Locking...\n";
$lock->lock("ABCD");
$lock->lock("test1");
$lock->lock("test2");
$lock->lock("test3");
print "Locked.\n";
sleep(3);
print "Un-Locking...\n";
$lock->unlock("test");
print "Unlocked.\n";
sleep(3);
test:
print "Locking...\n";
$lock->lock("test");
print "Locked.\n";
sleep(3);
print "Un-Locking.\n";
$lock->unlock("test");
print "Unlocked.\n";
sleep(3);
示例11: Lock
<?php
/**
* The page edit form.
*/
$page->layout = 'admin';
if (!User::require_admin()) {
$this->redirect('/admin');
}
$lock = new Lock('Webpage', $_GET['page']);
if ($lock->exists()) {
$page->title = i18n_get('Editing Locked');
echo $tpl->render('admin/locked', $lock->info());
return;
} else {
$lock->add();
}
require_once 'apps/admin/lib/Functions.php';
$wp = new Webpage($_GET['page']);
$f = new Form('post', 'admin/edit');
$f->verify_csrf = false;
if ($f->submit()) {
$wp->id = $_POST['id'];
$wp->title = $_POST['title'];
$wp->menu_title = $_POST['menu_title'];
$wp->window_title = $_POST['window_title'];
$wp->access = $_POST['access'];
$wp->layout = $_POST['layout'];
$wp->description = $_POST['description'];
$wp->keywords = $_POST['keywords'];
$wp->body = $_POST['body'];
示例12: foreach
<div class="col-md-12">
<fieldset>
<legend>Locks</legend>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Selection</th>
<th>Serial</th>
<th>Address</th>
<th>Model</th>
</tr>
</thead>
<tbody id='locks'>
<?php
$locks = Lock::searchByOwner($_SESSION['identification']);
$counter = 1;
foreach ($locks as $lock) {
$row = "<tr>" . "<td>" . $counter++ . "</td>" . "<td><input type='radio' name='locks' onchange='showCodes(selectLock())' value='" . $lock->serial() . "'></td>" . "<td>" . $lock->serial() . "</td>" . "<td>" . $lock->address() . "</td>" . "<td>" . $lock->model() . "</td>" . "</tr>";
echo $row;
}
?>
</tbody>
</table>
</fieldset>
</div>
</div>
</div>
</div>
<div class="section">
<div class="container">
示例13: Owner
<?php
require_once 'class/HelperOfBailiff.php';
require_once 'class/Lock.php';
require_once 'class/LockMaster.php';
require_once 'class/Owner.php';
$owner = new Owner();
$owner->setIsPresent(true);
$owner->setAgrees(false);
$lock = new Lock();
$lock->setIsLocked(true);
$helperOfBailiff = new HelperOfBailiff();
$helperOfBailiff->order($owner, $lock);
echo ' 100: Kas uks on lukus?' . $lock->getIsLocked();
示例14: get_related_Kbits
/**
* returns list of terms that are related to object
* @param {array} $object_UID array of type array("column_name"=>'DELIVERY_BASE_ID', "value"=>5)
* @param {string} $link_type The link type
* @param {string} $tableName Table name of the relation which depends on object type, e.g. R_LD2T, R_LK2T.
* @param {string} $lang The required language, if no language is selected all languages will be returned
* @return {array:terms} array of terms
*/
public static function get_related_Kbits($Delivery_UID, $user)
{
$NEEDED = array();
$PROVIDED = array();
$OTHERS = array();
// get database name
if (Lock::is_locked_by_user($Delivery_UID, 'DELIVERY_BASE', $user) == true) {
$database_name = dbAPI::get_db_name('user');
} else {
$database_name = dbAPI::get_db_name('content');
}
$dbObj = new dbAPI();
// get all needed and provide Kbits (as relation objects)
$query = "SELECT * FROM R_LD2K where ENABLED = 1 AND (DELIVERY_BASE_ID = " . $Delivery_UID . ")";
$results = $dbObj->db_select_query($database_name, $query);
for ($i = 0; $i < count($results); $i++) {
$curr_Kbit = Kbit::get_Kbit_details($results[$i]["KBIT_BASE_ID"], $user);
if ($results[$i]["LINK_TYPE"] == 'NEEDED') {
array_push($NEEDED, $curr_Kbit);
} else {
if ($results[$i]["LINK_TYPE"] == 'PROVIDED') {
array_push($PROVIDED, $curr_Kbit);
} else {
array_push($OTHERS, $curr_Kbit);
}
}
}
$kbits = array("NEEDED" => $NEEDED, "PROVIDED" => $PROVIDED, "OTHERS" => $OTHERS);
return $kbits;
}
示例15: foreach
} else {
foreach (array_keys($config) as $key) {
if (isset($_GET[$key])) {
$config[$key] = $_GET[$key];
}
}
}
return $config;
}
$config = getParams();
// if requested, clear the lock
if ($config['fix-lock']) {
if (Lock::release('process_mail_queue')) {
echo "The lock file was removed successfully.\n";
}
exit(0);
}
if (!Lock::acquire('process_mail_queue')) {
$pid = Lock::getProcessID('process_mail_queue');
fwrite(STDERR, "ERROR: There is already a process (pid={$pid}) of this script running.");
fwrite(STDERR, "If this is not accurate, you may fix it by running this script with '--fix-lock' as the only parameter.\n");
exit(1);
}
// handle only pending emails
$limit = 50;
Mail_Queue::send('pending', $limit);
// handle emails that we tried to send before, but an error happened...
$limit = 50;
Mail_Queue::send('error', $limit);
Lock::release('process_mail_queue');