PHP Queue class Message Queuing thinkphp queue PHP queue processing high and

Source: Internet
Author: User
Tags php class

    /** * PHP Class for queue * @author yangqijun@live.cn * @copyright Datafrog Beijingbei Ltd. 2011 -07-25 * * classQueue { Public$length= A;//default queue, equivalent to initialize queue 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 */ Public functionrun($param) {if(!is_array ($this->queue)) {$this->strtoque ();//Treat an array as a queue}$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)//If it is an empty queue, the queue is initialized to the input queue{$param=Empty($param)?0:$param;$this->queue[]=$param; }Else{ for($i=0;$i<$currentlength-$this->length-1;$i++)//Queue more than the specified queue, to delete the first element in order to be queued{$this->queremove (); }$this->queadd ($param); }return$this->queue; }/** * string like the "22,23,24" convert to array to do queue * @param string $string * @param String $delimiter * / Public functionstrtoque(){if(Empty($this->queue)) {$this->queue=Array(); }Else{$this->queue=explode ($this->delimiter,$this->queue); } }/** * Insert $node into queue * @param string $node */Private functionqueadd($node){Array_push ($this->queue,$node);$this->countqueue (); }Private functionqueremove(){$node= Array_shift ($this->queue);$this->countqueue ();return$node; }Private functioncountqueue(){$currentlength= Count ($this->queue);return$currentlength; } function__destruct() {unset($this->queue); } }//example$str=' 88|89|90|56|23|45|69|23|20|100 ';$obj=NewQueue ($str);$obj->length=8;//Queue element length$obj->delimiter='|';//If the queue is a string, the element's immediate delimiter is |$a=$obj->run (' the ');//elements to be added to the queue$a=$obj->run (' the ");$a=$obj->run (' the ' ");$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); }); });

    The above describes the PHP queue class, including PHP, queue content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.