当前位置: 首页>>代码示例>>PHP>>正文


PHP resource::setTimeout方法代码示例

本文整理汇总了PHP中resource::setTimeout方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::setTimeout方法的具体用法?PHP resource::setTimeout怎么用?PHP resource::setTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在resource的用法示例。


在下文中一共展示了resource::setTimeout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _get_lock

 /**
  * Get lock
  *
  * Acquires an (emulated) lock.
  *
  * @param	string	$session_id	Session ID
  * @return	bool
  */
 protected function _get_lock($session_id)
 {
     if (isset($this->_lock_key)) {
         return $this->_redis->setTimeout($this->_lock_key, 300);
     }
     // 30 attempts to obtain a lock, in case another request already has it
     $lock_key = $this->_key_prefix . $session_id . ':lock';
     $attempt = 0;
     do {
         if (($ttl = $this->_redis->ttl($lock_key)) > 0) {
             sleep(1);
             continue;
         }
         if (!$this->_redis->setex($lock_key, 300, time())) {
             log_message('error', 'Session: Error while trying to obtain lock for ' . $this->_key_prefix . $session_id);
             return FALSE;
         }
         $this->_lock_key = $lock_key;
         break;
     } while (++$attempt < 30);
     if ($attempt === 30) {
         log_message('error', 'Session: Unable to obtain lock for ' . $this->_key_prefix . $session_id . ' after 30 attempts, aborting.');
         return FALSE;
     } elseif ($ttl === -1) {
         log_message('debug', 'Session: Lock for ' . $this->_key_prefix . $session_id . ' had no TTL, overriding.');
     }
     $this->_lock = TRUE;
     return TRUE;
 }
开发者ID:wms-code,项目名称:CodeIgniter-admin,代码行数:37,代码来源:Session_redis_driver.php

示例2: _get_lock

 /**
  * Get lock
  *
  * Acquires an (emulated) lock.
  *
  * @param	string	$session_id	Session ID
  * @return	bool
  */
 protected function _get_lock($session_id)
 {
     if (isset($this->_lock_key)) {
         return $this->_redis->setTimeout($this->_lock_key, 300);
     }
     // 30 attempts to obtain a lock, in case another request already has it
     $lock_key = $this->_key_prefix . $session_id . ':lock';
     $attempt = 0;
     do {
         if (($ttl = $this->_redis->ttl($lock_key)) > 0) {
             sleep(1);
             continue;
         }
         if (!$this->_redis->setex($lock_key, 300, time())) {
             return FALSE;
         }
         $this->_lock_key = $lock_key;
         break;
     } while (++$attempt < 30);
     if ($attempt === 30) {
         return FALSE;
     }
     $this->_lock = TRUE;
     return TRUE;
 }
开发者ID:evolutionscript,项目名称:CI_Session,代码行数:33,代码来源:Session_redis_driver.php

示例3: _get_lock

 /**
  * Get lock.
  *
  * Acquires an (emulated) lock.
  *
  * @param string $session_id Session ID
  *
  * @return bool
  */
 protected function _get_lock($session_id)
 {
     // PHP 7 reuses the SessionHandler object on regeneration,
     // so we need to check here if the lock key is for the
     // correct session ID.
     if ($this->_lock_key === $this->_key_prefix . $session_id . ':lock') {
         return $this->_redis->setTimeout($this->_lock_key, 300);
     }
     // 30 attempts to obtain a lock, in case another request already has it
     $lock_key = $this->_key_prefix . $session_id . ':lock';
     $attempt = 0;
     do {
         if (($ttl = $this->_redis->ttl($lock_key)) > 0) {
             sleep(1);
             continue;
         }
         if (!$this->_redis->setex($lock_key, 300, time())) {
             log_message('error', 'Session: Error while trying to obtain lock for ' . $this->_key_prefix . $session_id);
             return false;
         }
         $this->_lock_key = $lock_key;
         break;
     } while (++$attempt < 30);
     if ($attempt === 30) {
         log_message('error', 'Session: Unable to obtain lock for ' . $this->_key_prefix . $session_id . ' after 30 attempts, aborting.');
         return false;
     } elseif ($ttl === -1) {
         log_message('debug', 'Session: Lock for ' . $this->_key_prefix . $session_id . ' had no TTL, overriding.');
     }
     $this->_lock = true;
     return true;
 }
开发者ID:recca0120,项目名称:laraigniter,代码行数:41,代码来源:Session_redis_driver.php

示例4: write

 /**
  * Write
  *
  * Writes (create / update) session data
  *
  * @param	string	$session_id	Session ID
  * @param	string	$session_data	Serialized session data
  * @return	bool
  */
 public function write($session_id, $session_data)
 {
     if (!isset($this->_redis)) {
         return $this->_fail();
     } elseif ($session_id !== $this->_session_id) {
         if (!$this->_release_lock() or !$this->_get_lock($session_id)) {
             return $this->_fail();
         }
         $this->_key_exists = FALSE;
         $this->_session_id = $session_id;
     }
     if (isset($this->_lock_key)) {
         $this->_redis->setTimeout($this->_lock_key, 300);
         if ($this->_fingerprint !== ($fingerprint = md5($session_data)) or $this->_key_exists === FALSE) {
             if ($this->_redis->set($this->_key_prefix . $session_id, $session_data, $this->_config['expiration'])) {
                 $this->_fingerprint = $fingerprint;
                 $this->_key_exists = TRUE;
                 return $this->_success;
             }
             return $this->_fail();
         }
         return $this->_redis->setTimeout($this->_key_prefix . $session_id, $this->_config['expiration']) ? $this->_success : $this->_fail();
     }
     return $this->_fail();
 }
开发者ID:jimok82,项目名称:CIOpenReview,代码行数:34,代码来源:Session_redis_driver.php

示例5: _get_lock

 /**
  * Get lock
  *
  * Acquires an (emulated) lock.
  *
  * @param	string	$session_id	Session ID
  * @return	bool
  */
 protected function _get_lock($session_id)
 {
     if (isset($this->_lock_key)) {
         return $this->_redis->setTimeout($this->_lock_key, 5);
     }
     $lock_key = $this->_key_prefix . $session_id . ':lock';
     if (($ttl = $this->_redis->ttl($lock_key)) < 1) {
         if (!$this->_redis->setex($lock_key, 5, time())) {
             log_message('error', 'Session: Error while trying to obtain lock for ' . $this->_key_prefix . $session_id);
             return FALSE;
         }
         $this->_lock_key = $lock_key;
         if ($ttl === -1) {
             log_message('debug', 'Session: Lock for ' . $this->_key_prefix . $session_id . ' had no TTL, overriding.');
         }
         $this->_lock = TRUE;
         return TRUE;
     }
     // Another process has the lock, we'll try to wait for it to free itself ...
     $attempt = 0;
     while ($attempt++ < 5) {
         usleep($ttl * 1000000 - 20000);
         if (($ttl = $this->_redis->ttl($lock_key)) > 0) {
             continue;
         }
         if (!$this->_redis->setex($lock_key, 5, time())) {
             log_message('error', 'Session: Error while trying to obtain lock for ' . $this->_key_prefix . $session_id);
             return FALSE;
         }
         $this->_lock_key = $lock_key;
         break;
     }
     if ($attempt === 5) {
         log_message('error', 'Session: Unable to obtain lock for ' . $this->_key_prefix . $session_id . ' after 5 attempts, aborting.');
         return FALSE;
     }
     $this->_lock = TRUE;
     return TRUE;
 }
开发者ID:acamboy,项目名称:Codeigniter-3.0-with-XHMVC,代码行数:47,代码来源:Session_redis_driver.php

示例6: setTimeout

 /**
  * Set the socket I/O timeout value in seconds plus microseconds.
  *
  * @param   integer $seconds        Timeout value in seconds.
  * @param   integer $microseconds   Additional value in microseconds.
  *
  * @access  public
  * @since   1.5.0
  */
 function setTimeout($seconds, $microseconds = 0)
 {
     return $this->_socket->setTimeout($seconds, $microseconds);
 }
开发者ID:rbraband,项目名称:sefrengo,代码行数:13,代码来源:SMTP.php


注:本文中的resource::setTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。