队列(Queue)是运算受到限制的一种线性表。只允许在表的一端进行插入,而在另一端进行删除元素的线性表。队尾(rear)是允许插入的一端。队头(front)是允许删
一:队列的概念、数据结构
队列(Queue)是运算受到限制的一种线性表。只允许在表的一端进行插入,而在另一端进行删除元素的线性表。队尾(rear)是允许插入的一端。队头(front)是允许删除的一端。空队列是不含元素的空表。
假设有个队列Q=(a1,a2,…,an),则a1为队头元素,an为队尾元素。元素入队的次序为a1,a2,…,an,而出队的次序为a1,a2,…,an。可见队列的操作是按照先进先出的原则进行的。
其他详细的介绍请在网上搜索很多资料。
二:PHP的队列
在PHP中队列以数组的形式表现。数组中的第一个元素作为队头,最后一个元素作为队尾,这样就可以操作这个队列了。
结果就是
网上有很多封装好的类,可以直接使用。
array_push:将一个或多个单元压入数组的末尾(入栈)
array_unshift:在数组开头插入一个或多个单元
array_pop:将数组最后一个单元弹出(出栈)
array_shift:将数组开头的单元移出数组
三:Ruby Starling
Starling是一个支持MemCache协议的轻量级持久化服务器。Starling是让创建网络访问队列或者多个队列异常简单,也就是说多点和多台机器间的异步工作进程。它是著名微博客网站Twitter开发用来处理大量的队列消息,以及保持服务的响应。Starling已经在生产环境中使用,不仅是Twitter在使用,FiveRuns同样在使用。FiveRuns甚至还根据自己的应用做了改进。
Starling和Memcache使用的是一个协议只是端口不一样。Starling使用的是22122端口,美国服务器,Memcache使用的是11211端口。
Ruby
tar xzvf ruby-1.9.1-p0.tar.gz
cd ruby-1.9.1-p0
./configure --prefix=/usr/local/huiyangruby
make
make install
Gem
tar -zxvf rubygems-1.3.6.tgz
cd rubygems-1.3.6
ruby setup.rb
Starling
gem install memcache-client starling
starling
starling & //后台执行
starling_top //查看PS信息
接下来你就可以使用队列做自己的事情啦。Starling和Memcache用法一样,两者配合处理更佳。
使用Memcache::addServer可以建立一个memcache连接池。他不同于connect与pconnect他是在有请求是才连接,无则端口连接。
Memcache::connect -- 打开一个到Memcache的连接。
Memcache::pconnect -- 打开一个到Memcache的长连接。
Memcache::close -- 关闭一个Memcache的连接。
Memcache::set -- 保存数据到Memcache服务器上。
Memcache::get -- 提取一个保存在Memcache服务器上的数据。
Memcache::replace -- 替换一个已经存在Memcache服务器上的项目(功能类似Memcache::set)。
Memcache::delete -- 从Memcache服务器上删除一个保存的项目。
Memcache::flush -- 刷新所有Memcache服务器上保存的项目(类似于删除所有的保存的项目)。
Memcache::getStats -- 获取当前Memcache服务器运行的状态。
四:张宴作品HTTPSQS
HTTPSQS(HTTP Simple Queue Service)是一款基于 HTTP GET/POST 协议的轻量级开源简单消息队列服务,网站空间,使用 Tokyo Cabinet 的 B+Tree Key/Value 数据库来做数据的持久化存储。
有兴趣的可以看看网址:
五:队列的应用
队列可以很好地异步处理数据传送和存储,当你频繁地向数据库中插入数据、频繁地向搜索引擎提交数据,就可采取队列来异步插入。另外,还可以将较慢的处理逻辑、有并发数量限制的处理逻辑,通过消息队列放在后台处理,虚拟主机,例如FLV视频转换、发送手机短信、发送电子邮件等。(文/侯惠阳 PHPer.yang)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.