加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php-beanstalkd消息队列类实例分享

发布时间:2021-02-02 22:18:19 所属栏目:PHP教程 来源:网络整理
导读:本文实例为大家分享了php beanstalkd消息队列类的具体代码,供大家参考,具体内容如下 use RuntimeException; /** An interface to the beanstalk queue service. Implements the beanstalk protocol spec 1.9. Where appropriate the documentation from th

/**

  • Inspect the job with the shortest delay left.
  • @return string|boolean false on error otherwise the body of the job.
    */
    public function peekDelayed() {
    $this->_write('peek-delayed');
    return $this->_peekRead();
    }

/**

  • Inspect the next job in the list of buried jobs.
  • @return string|boolean false on error otherwise the body of the job.
    */
    public function peekBuried() {
    $this->_write('peek-buried');
    return $this->_peekRead();
    }

/**

  • Handles response for all peek methods.
  • @return string|boolean false on error otherwise the body of the job.
    */
    protected function _peekRead() {
    $status = strtok($this->_read(),' ');
switch ($status) {
  case 'FOUND':
    return [
      'id' => (integer) strtok(' '),'body' => $this->_read((integer) strtok(' '))
    ];
  case 'NOT_FOUND':
  default:
    $this->_error($status);
    return false;
}

}

/**

  • Moves jobs into the ready queue (applies to the current tube).
  • If there are buried jobs those get kicked only otherwise delayed
  • jobs get kicked.
  • @param integer $bound Upper bound on the number of jobs to kick.
  • @return integer|boolean False on error otherwise number of jobs kicked.
    */
    public function kick($bound) {
    $this->_write(sprintf('kick %d',$bound));
    $status = strtok($this->_read(),' ');
switch ($status) {
  case 'KICKED':
    return (integer) strtok(' ');
  default:
    $this->_error($status);
    return false;
}

}

/**

  • This is a variant of the kick command that operates with a single
  • job identified by its job id. If the given job id exists and is in a
  • buried or delayed state,it will be moved to the ready queue of the
  • the same tube where it currently belongs.
  • @param integer $id The job id.
  • @return boolean false on error true otherwise.
    */
    public function kickJob($id) {
    $this->_write(sprintf('kick-job %d',$id));
    $status = strtok($this->_read(),' ');
switch ($status) {
  case 'KICKED':
    return true;
  case 'NOT_FOUND':
  default:
    $this->_error($status);
    return false;
}

}

/ Stats Commands /

/**

  • Gives statistical information about the specified job if it exists.
  • @param integer $id The job id.
  • @return string|boolean false on error otherwise a string with a yaml formatted dictionary.
    */
    public function statsJob($id) {
    $this->_write(sprintf('stats-job %d',$id));
    return $this->_statsRead();
    }

/**

  • Gives statistical information about the specified tube if it exists.
  • @param string $tube Name of the tube.
  • @return string|boolean false on error otherwise a string with a yaml formatted dictionary.
    */
    public function statsTube($tube) {
    $this->_write(sprintf('stats-tube %s',$tube));
    return $this->_statsRead();
    }

/**

  • Gives statistical information about the system as a whole.
  • @return string|boolean false on error otherwise a string with a yaml formatted dictionary.
    */
    public function stats() {
    $this->_write('stats');
    return $this->_statsRead();
    }

/**

  • Returns a list of all existing tubes.
  • @return string|boolean false on error otherwise a string with a yaml formatted list.
    */
    public function listTubes() {
    $this->_write('list-tubes');
    return $this->_statsRead();
    }

/**

  • Returns the tube currently being used by the producer.
  • @return string|boolean false on error otherwise a string with the name of the tube.
    */
    public function listTubeUsed() {
    $this->_write('list-tube-used');
    $status = strtok($this->_read(),' ');
switch ($status) {
  case 'USING':
    return strtok(' ');
  default:
    $this->_error($status);
    return false;
}

}

/**

  • Returns a list of tubes currently being watched by the worker.
  • @return string|boolean false on error otherwise a string with a yaml formatted list.
    */
    public function listTubesWatched() {
    $this->_write('list-tubes-watched');
    return $this->_statsRead();
    }

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读