本文整理汇总了PHP中eaccelerator_lock函数的典型用法代码示例。如果您正苦于以下问题:PHP eaccelerator_lock函数的具体用法?PHP eaccelerator_lock怎么用?PHP eaccelerator_lock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eaccelerator_lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: putInCache
/**
* Put data into remote cache store
*
* @param string Cache unique key
* @param string Cache value to add
* @param integer [Optional] Time to live
* @return @e boolean
*/
public function putInCache($key, $value, $ttl = 0)
{
eaccelerator_lock(md5($this->identifier . $key));
$check = eaccelerator_put(md5($this->identifier . $key), $value, intval($ttl));
eaccelerator_unlock(md5($this->identifier . $key));
return $check;
}
示例2: set
/**
* 写入缓存
* @access public
* @param string $name 缓存变量名
* @param mixed $value 存储数据
* @param integer $expire 有效时间(秒)
* @return boolen
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}
$name = $this->options['prefix'] . $name;
eaccelerator_lock($name);
if (eaccelerator_put($name, $value, $expire)) {
if ($this->options['length'] > 0) {
// 记录缓存队列
$queue = eaccelerator_get('__info__');
if (!$queue) {
$queue = [];
}
if (false === array_search($name, $queue)) {
array_push($queue, $name);
}
if (count($queue) > $this->options['length']) {
// 出列
$key = array_shift($queue);
// 删除缓存
eaccelerator_rm($key);
}
eaccelerator_put('__info__', $queue);
}
return true;
}
return false;
}
示例3: put
/**
* Write an item to the cache.
*
* @param string The name of the cache
* @param mixed The data to write to the cache item
* @return boolean True on success, false on failure
*/
function put($name, $contents)
{
eaccelerator_lock($this->unique_id . "_" . $name);
$status = eaccelerator_put($this->unique_id . "_" . $name, serialize($contents));
eaccelerator_unlock($this->unique_id . "_" . $name);
return $status;
}
示例4: delData
/**
* Delete cache from shared memory
*
* @param string $sKey - file name
* @return result of the operation
*/
function delData($sKey)
{
eaccelerator_lock($sKey);
eaccelerator_rm($sKey);
eaccelerator_unlock($sKey);
return true;
}
示例5: put
function put($name, $data, $ttl = 604800)
{
$ttl = (int) $ttl ? (int) $ttl : 604800;
if (eaccelerator_lock($this->key . $name)) {
eaccelerator_put($this->key . $name, serialize($data), $ttl);
eaccelerator_unlock($this->key . $name);
}
$this->vars[$name] = $data;
}
示例6: set
public function set($key, $value, $type = '', $ttl = SESSION_EXPIRE)
{
$this->type = $type;
$name = $this->_key($key);
eaccelerator_lock($name);
if (eaccelerator_put($name, $value, $ttl)) {
return true;
}
return false;
}
示例7: set
public function set($key, $value, $type = "", $ttl = SESSION_EXPIRE)
{
$this->type = $type;
$name = $this->_key($key);
eaccelerator_lock($name);
if (eaccelerator_put($name, $value, $ttl)) {
return TRUE;
}
return FALSE;
}
示例8: set
/**
+----------------------------------------------------------
* 写入缓存
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缓存变量名
* @param mixed $value 存储数据
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function set($name, $value, $ttl = null)
{
N('cache_write', 1);
if (isset($ttl) && is_int($ttl)) {
$expire = $ttl;
} else {
$expire = $this->expire;
}
eaccelerator_lock($name);
return eaccelerator_put($name, $value, $expire);
}
示例9: lock
/**
* Enter description here ...
*/
public function lock()
{
if (!$this->eAccelerator) {
$this->fp = fopen($this->path, 'w+');
if ($this->fp === false) {
return false;
}
return flock($this->fp, LOCK_EX);
} else {
return eaccelerator_lock($this->name);
}
}
示例10: write
/**
* write template to cache
*
* @access public
* @param string cache key
* @param array templates to store
* @return boolean true on success
*/
function write($key, $templates)
{
if (!function_exists('eaccelerator_lock')) {
return false;
}
eaccelerator_lock($key);
if ($this->getParam('lifetime') == 'auto') {
eaccelerator_put($key, serialize($templates));
} else {
eaccelerator_put($key, serialize($templates), $this->getParam('lifetime') * 60);
}
eaccelerator_unlock($key);
return true;
}
示例11: lock
/**
* 加锁
* Enter description here ...
*/
public function lock()
{
//如果无法开启ea内存锁,则开启文件锁
if (!$this->eAccelerator) {
//配置目录权限可写
$this->fp = fopen($this->path, 'w+');
if ($this->fp === false) {
return false;
}
return flock($this->fp, LOCK_EX);
} else {
return eaccelerator_lock($this->name);
}
}
示例12: set
/**
+----------------------------------------------------------
* 写入缓存
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缓存变量名
* @param mixed $value 存储数据
* @param integer $expire 有效时间(秒)
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function set($name, $value, $expire = null)
{
N('cache_write', 1);
if (is_null($expire)) {
$expire = $this->options['expire'];
}
eaccelerator_lock($name);
if (eaccelerator_put($name, $value, $expire)) {
if ($this->options['length'] > 0) {
// 记录缓存队列
$this->queue($name);
}
return true;
}
return false;
}
示例13: set
public function set($key, $value = "", $ttl = 300, $mode = 0)
{
if (empty($value)) {
return eaccelerator_rm($key);
} else {
eaccelerator_lock($key);
switch ($mode) {
case 1:
return eaccelerator_cache_output($key, $value, $ttl);
break;
case 2:
return eaccelerator_cache_result($key, $value, $ttl);
break;
default:
return eaccelerator_put($key, $value, $ttl);
}
eaccelerator_unlock($key);
}
}
示例14: smarty_cache_eaccelerator
/**
* Smarty Cache Handler<br>
* utilizing eAccelerator extension (http://eaccelerator.net/HomeUk)<br>
*
* Name: smarty_cache_eaccelerator<br>
* Type: Cache Handler<br>
* Purpose: Replacement for the file based cache handling of Smarty. smarty_cache_eaccelerator() is
* using Turck eaccelerator extension to minimize disk usage.
* File: cache.eaccelerator.php<br>
* Date: Dec 2, 2003<br>
*
* Usage Example<br>
* <pre>
* $smarty = new Smarty;
* $smarty->cache_handler_func = 'smarty_cache_eaccelerator';
* $smarty->caching = true;
* $smarty->display('index.tpl');
* </pre>
*
* @author André Rabold
* @version RC-1
*
* @param string $action Cache operation to perform ( read | write | clear )
* @param mixed $smarty Reference to an instance of Smarty
* @param string $cache_content Reference to cached contents
* @param string $tpl_file Template file name
* @param string $cache_id Cache identifier
* @param string $compile_id Compile identifier
* @param integer $exp_time Expiration time
* @return boolean TRUE on success, FALSE otherwise
*
* @link http://eaccelerator.net/HomeUk
* (eaccelerator homepage)
* @link http://smarty.php.net/manual/en/section.template.cache.handler.func.php
* (Smarty online manual)
*/
function smarty_cache_eaccelerator($action, &$smarty, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null)
{
if(!function_exists("eaccelerator")) {
$smarty->trigger_error("cache_handler: PHP Extension \"eaccelerator\" (http://eaccelerator.net/HomeUk) not installed.");
return false;
}
// Create unique cache id:
// We are using smarty's internal functions here to be as compatible as possible.
$_auto_id = $smarty->_get_auto_id($cache_id, $compile_id);
$_cache_file = substr($smarty->_get_auto_filename(".", $tpl_file, $_auto_id),2);
$eaccelerator_id = "smarty_eaccelerator|".$_cache_file;
// The index contains all stored cache ids in a hierarchy and can be iterated later
$eaccelerator_index_id = "smarty_eaccelerator_index";
switch ($action) {
case 'read':
// read cache from shared memory
$cache_content = eaccelerator_get($eaccelerator_id);
if (!is_null($cache_content) && _eaccelerator_hasexpired($cache_content)) {
// Cache has been expired so we clear it now by calling ourself with another parameter :)
$cache_content = null;
smarty_cache_eaccelerator('clear', $smarty, $cache_content, $tpl_file, $cache_id, $compile_id);
}
$return = true;
break;
case 'write':
// save cache to shared memory
$current_time = time();
if (is_null($exp_time) || $exp_time < $current_time)
$ttl = 0;
else
$ttl = $exp_time - time();
// First run garbage collection
eaccelerator_gc();
// Put content into cache
eaccelerator_lock($eaccelerator_id);
eaccelerator_put($eaccelerator_id, $cache_content, $ttl);
// Create an index association
eaccelerator_lock($eaccelerator_index_id);
$eaccelerator_index = eaccelerator_get($eaccelerator_index_id);
if (!is_array($eaccelerator_index))
$eaccelerator_index = array();
$indexes = explode(DIRECTORY_SEPARATOR, $_cache_file);
$_pointer =& $eaccelerator_index;
foreach ($indexes as $index) {
if (!isset($_pointer[$index]))
$_pointer[$index] = array();
$_pointer =& $_pointer[$index];
}
$_pointer = $eaccelerator_id;
eaccelerator_put($eaccelerator_index_id, $eaccelerator_index, 0);
eaccelerator_unlock($eaccelerator_index_id);
eaccelerator_unlock($eaccelerator_id);
break;
//.........这里部分代码省略.........
示例15: downloadSubject
//.........这里部分代码省略.........
return null;
// 並列ダウンロード済の場合も抜ける
} elseif (!empty($GLOBALS['expack.subject.multi-threaded-download.done'])) {
return null;
// 新規スレ立て時以外で、キャッシュが新鮮な場合も抜ける
} elseif (empty($_POST['newthread']) and $this->isSubjectTxtFresh()) {
return null;
}
}
$modified = gmdate("D, d M Y H:i:s", filemtime($this->subject_file)) . " GMT";
}
}
$dlStartTime = $this->microtimeFloat();
// DL
require_once 'HTTP/Request.php';
$params = array();
$params['timeout'] = $_conf['fsockopen_time_limit'];
if ($_conf['proxy_use']) {
$params['proxy_host'] = $_conf['proxy_host'];
$params['proxy_port'] = $_conf['proxy_port'];
}
$req = new HTTP_Request($this->subject_url, $params);
$modified && $req->addHeader('If-Modified-Since', $modified);
$req->addHeader('User-Agent', sprintf('Monazilla/1.00 (%s/%s)', $_conf['p2uaname'], $_conf['p2version']));
$response = $req->sendRequest();
$error_msg = null;
if (PEAR::isError($response)) {
$error_msg = $response->getMessage();
} else {
$code = $req->getResponseCode();
if ($code == 302) {
// ホストの移転を追跡
require_once P2_LIB_DIR . '/BbsMap.php';
$new_host = BbsMap::getCurrentHost($this->host, $this->bbs);
if ($new_host != $this->host) {
$aNewSubjectTxt = new SubjectTxt($new_host, $this->bbs);
return $aNewSubjectTxt->downloadSubject();
}
}
if (!($code == 200 || $code == 206 || $code == 304)) {
//var_dump($req->getResponseHeader());
$error_msg = $code;
}
}
if (!is_null($error_msg) && strlen($error_msg) > 0) {
$attrs = array();
if ($_conf['ext_win_target']) {
$attrs['target'] = $_conf['ext_win_target'];
}
$atag = P2View::tagA(P2Util::throughIme($this->subject_url), hs($this->subject_url), $attrs);
$msg_ht = sprintf('<div>Error: %s<br>p2 info - %s に接続できませんでした。</div>', hs($error_msg), $atag);
P2Util::pushInfoHtml($msg_ht);
$body = '';
} else {
$body = $req->getResponseBody();
}
$dlEndTime = $this->microtimeFloat();
$dlTime = $dlEndTime - $dlStartTime;
$spentDlTime_ += $dlTime;
// DL成功して かつ 更新されていたら
if ($body && $code != '304') {
// したらば or be.2ch.net ならEUCをSJISに変換
if (P2Util::isHostJbbsShitaraba($this->host) || P2Util::isHostBe2chNet($this->host)) {
$body = mb_convert_encoding($body, 'SJIS-win', 'eucJP-win');
}
// eaccelerator or apcに保存する場合
if ($this->storage == 'eaccelerator' || $this->storage == 'apc') {
$cache_key = "{$this->host}/{$this->bbs}";
$cont = rtrim($body);
$lines = explode("\n", $cont);
if ($this->storage == 'eaccelerator') {
eaccelerator_lock($cache_key);
eaccelerator_put($cache_key, $lines, $_conf['sb_dl_interval']);
eaccelerator_unlock($cache_key);
} else {
apc_store($cache_key, $lines, $_conf['sb_dl_interval']);
}
return $lines;
// ファイルに保存する場合
} else {
if (false === FileCtl::filePutRename($this->subject_file, $body)) {
// 保存に失敗はしても、既存のキャッシュが読み込めるならよしとしておく
if (is_readable($this->subject_file)) {
return null;
} else {
die("Error: cannot write file");
return false;
}
}
chmod($this->subject_file, $perm);
}
} else {
// touchすることで更新インターバルが効くので、しばらく再チェックされなくなる
// (変更がないのに修正時間を更新するのは、少し気が進まないが、ここでは特に問題ないだろう)
if ($this->storage == 'file') {
touch($this->subject_file);
}
}
return null;
}