奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

php語言

PHP隊列是什么

時間:2025-03-22 09:12:14 php語言 我要投稿

PHP隊列是什么

  PHP具有非常強大的功能,所有的CGI的功能PHP都能實現(xiàn),而且支持幾乎所有流行的數(shù)據(jù)庫以及操作系統(tǒng)。最重要的是PHP可以用C、C++進行程序的擴展!今天,小編為大家搜索整理了PHP隊列是什么,希望大家能有所收獲,更多精彩內容請持續(xù)關注我們應屆畢業(yè)生考試網!

  什么是隊列,是先進先出的線性表,在具體應用中通常用鏈表或者數(shù)組來實現(xiàn),隊列只允許在后端進行插入操作,在前端進行刪除操作。

  什么情況下會用了隊列呢,并發(fā)請求又要保證事務的完整性的時候就會用到隊列,當然不排除使用其它更好的方法,知道的不仿說說看。

  隊列還可以用于減輕數(shù)據(jù)庫服務器壓力,我們可以將不是即時數(shù)據(jù)放入到隊列中,在數(shù)據(jù)庫空閑的時候或者間隔一段時間后執(zhí)行。比如訪問計數(shù)器,沒有必要即時的執(zhí)行訪問增加的Sql,在沒有使用隊列的時候sql語句是這樣的,假設有5個人訪問:

  update table1 set count=count+1 where id=1

  update table1 set count=count+1 where id=1

  update table1 set count=count+1 where id=1

  update table1 set count=count+1 where id=1

  update table1 set count=count+1 where id=1

  而使用隊列這后就可以這樣:

  update table1 set count=count+5 where id=1

  減少sql請求次數(shù),從而達到減輕服務器壓力的效果, 當然訪問量不是很大網站根本沒有這個必要。

  下面一個隊列類:

  /**

  * 隊列

  *

  * @author jaclon

  *

  */

  class Queue

  {

  private $_queue = array();

  protected $cache = null;

  protected $queuecachename;

  /**

  * 構造方法

  * @param string $queuename 隊列名稱

  */

  function __construct($queuename)

  {

  $this->cache =& Cache::instance();

  $this->queuecachename = 'queue_' . $queuename;

  $result = $this->cache->get($this->queuecachename);

  if (is_array($result)) {

  $this->_queue = $result;

  }

  }

  /**

  * 將一個單元單元放入隊列末尾

  * @param mixed $value

  */

  function enQueue($value)

  {

  $this->_queue[] = $value;

  $this->cache->set($this->queuecachename, $this->_queue);

  return $this;

  }

  /**

  * 將隊列開頭的一個或多個單元移出

  * @param int $num

  */

  function sliceQueue($num = 1)

  {

  if (count($this->_queue) < $num) {

  $num = count($this->_queue);

  }

  $output = array_splice($this->_queue, 0, $num);

  $this->cache->set($this->queuecachename, $this->_queue);

  return $output;

  }

  /**

  * 將隊列開頭的單元移出隊列

  */

  function deQueue()

  {

  $entry = array_shift($this->_queue);

  $this->cache->set($this->queuecachename, $this->_queue);

  return $entry;

  }

  /**

  * 返回隊列長度

  */

  function size()

  {

  return count($this->_queue);

  }

  /**

  * 返回隊列中的第一個單元

  */

  function peek()

  {

  return $this->_queue[0];

  }

  /**

  * 返回隊列中的一個或多個單元

  * @param int $num

  */

  function peeks($num)

  {

  if (count($this->_queue) < $num) {

  $num = count($this->_queue);

  }

  return array_slice($this->_queue, 0, $num);

  }

  /**

  * 消毀隊列

  */

  function destroy()

  {

  $this->cache->remove($this->queuecachename);

  }

  }

【PHP隊列是什么】相關文章:

分析PHP隊列是什么10-05

php語言redis隊列操作實例08-19

php Memcache中實現(xiàn)消息隊列08-21

如何使用php操作redis隊列實例09-15

php是什么11-13

php中使用redis隊列操作實例代碼05-16

PHP的變量是什么06-10

PHP簡介是什么09-04

php語言是什么05-21

主站蜘蛛池模板: 石台县| 巍山| 留坝县| 邹平县| 安多县| 徐闻县| 海门市| 济阳县| 政和县| 遂宁市| 天峻县| 黄浦区| 长垣县| 凌云县| 盐津县| 荃湾区| 四平市| 中阳县| 年辖:市辖区| 沐川县| 乐东| 荆门市| 乐业县| 宁陵县| 荆州市| 钟祥市| 徐汇区| 满城县| 司法| 钟祥市| 旌德县| 鸡西市| 南通市| 成安县| 夏河县| 若羌县| 定日县| 乳源| 永靖县| 普格县| 湘阴县|