设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2021-01-27 16:34 所属栏目:121 来源:网络整理
导读:/** Handles responses for all stat methods. @param boolean $decode Whether to decode data before returning it or not. Default is true . @return array|string|boolean false on error otherwise statistic

/**

  • Handles responses for all stat methods.
  • @param boolean $decode Whether to decode data before returning it or not. Default is true.
  • @return array|string|boolean false on error otherwise statistical data.
    */
    protected function _statsRead($decode = true) {
    $status = strtok($this->_read(),' ');
switch ($status) {
  case 'OK':
    $data = $this->_read((integer) strtok(' '));
    return $decode ? $this->_decode($data) : $data;
  default:
    $this->_error($status);
    return false;
}

}

/**

  • Decodes YAML data. This is a super naive decoder which just works on
  • a subset of YAML which is commonly returned by beanstalk.
  • @param string $data The data in YAML format,can be either a list or a dictionary.
  • @return array An (associative) array of the converted data.
    */
    protected function _decode($data) {
    $data = array_slice(explode("\n",$data),1);
    $result = [];
foreach ($data as $key => $value) {
  if ($value[0] === '-') {
    $value = ltrim($value,'- ');
  } elseif (strpos($value,':') !== false) {
    list($key,$value) = explode(':',$value);
    $value = ltrim($value,' ');
  }
  if (is_numeric($value)) {
    $value = (integer) $value == $value ? (integer) $value : (float) $value;
  }
  $result[$key] = $value;
}
return $result;

}
}

?>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读