• 技术文章 >后端开发 >php教程

    php 队列类 消息队列 thinkphp 队列 php队列处理高并

    2016-07-29 08:52:05原创2519
    /** 
     * PHP Class for queue 
     * @author yangqijun@live.cn 
     * @copyright DataFrog Beijingbei  Ltd. 2011-07-25 
     */classQueue {public$length=12;          //默认队列,相当于初始化队列public$queue  = array();  //  if String like this "22,23,24"    convert to array to do queue  public$delimiter=',';  
    
        function__construct($queue=array())    {$this->queue=$queue;
        }  
        /** 
         * @desc start queue 
         * @param String  $param  new queue element 
         */publicfunctionrun($param)    {if(!is_array($this->queue)){  
                $this->strToQue();//将数组视为队列 
            }  
            $currentlength=$this->countqueue();        //Count  the  queue lengthecho$currentlength;
            echo$this->length.'
    '
    ; if($currentlength<$this->length&&$this->length>0) { $this->queAdd($param); }elseif($this->length==0) //如果为空队列,则将队列初始化为输入的队列 { $param=empty($param)?0:$param; $this->queue[]=$param; } else { for ($i=0;$i<$currentlength-$this->length-1;$i++)//队列比规定的队列多,要删掉队首的元素,才能入队 { $this->queRemove(); } $this->queAdd($param); } return$this->queue; } /** * String like this "22,23,24" convert to array to do queue * @param String $string * @param String $delimiter */publicfunctionstrToQue(){if (empty($this->queue)) { $this->queue=array(); } else { $this->queue=explode($this->delimiter,$this->queue); } } /** * insert $node into queue * @param string $node */privatefunctionqueAdd($node){ array_push($this->queue,$node); $this->countqueue(); } privatefunctionqueRemove(){$node = array_shift($this->queue); $this->countqueue(); return$node; } privatefunctioncountqueue(){$currentlength= count($this->queue); return$currentlength; } function__destruct() {unset($this->queue); } } //example $str='88|89|90|56|23|45|69|23|20|100'; $obj=new Queue ($str); $obj->length=8; // 队列元素长度 $obj->delimiter='|'; //如果队列是字符串,则元素直接的分隔符为| $a=$obj->run('91'); //要添加到队列中的元素 $a=$obj->run('92'); $a=$obj->run('93'); $a=$obj->run('94'); print_r($a); ?>

    ').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了php 队列类,包括了php,队列方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

    php入门到就业线上直播课:查看学习

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    ThinkPHP6基础与实战:点击学习

    课程从基础到实战详细分析讲解

    专题推荐:php 队列
    上一篇:DB2表数据迁移 db2命令 db2下载 db2数据库入门教 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)
  • 相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• 你知道如何用PHP实现多进程吗• PHP与MySQL连接的方法总结• 求解:phpcms模板怎样转码?该怎么解决• php 之 cookie 跟 session 简单解读(笔记)• php怎的快捷知道某个函数在哪个文件用过
    1/1

    PHP中文网