本文整理汇总了PHP中Codec::getEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP Codec::getEncode方法的具体用法?PHP Codec::getEncode怎么用?PHP Codec::getEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Codec
的用法示例。
在下文中一共展示了Codec::getEncode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNext
public function getNext()
{
if (time() - $this->pTime > 1) {
$this->pTime = time();
// MetaQ::$log->logDebug("current status:", array(
// 'id' => $this->id,
// 'group' => $this->group,
// 'topic' => $this->topic,
// 'offset' => $this->offset,
// 'sockets' => $this->sockets,
// 'partitionList' => $this->partitionList
// ));
$this->checkBalance();
}
if (sizeof($this->partitionList) == 0) {
return array();
}
$arr = $this->getCurrentPartition();
list($partition, $sleep, $master, $partId) = $arr;
list($host, $port, $pid) = explode('-', $partition);
$offset = $this->getOffset($master);
if (!isset($this->sockets[$host . ':' . $port])) {
$this->sockets[$host . ':' . $port] = new Socket($host, $port);
try {
$this->sockets[$host . ':' . $port]->connect();
} catch (\Exception $e) {
echo $e->getMessage();
}
}
$socket = $this->sockets[$host . ':' . $port];
$data = Codec::getEncode($this->topic, $this->group, $pid, $offset);
$socket->write($data);
$data = $socket->read(Codec::MAX_MSG_LENGTH + 14);
list($msgs, $offset, $_offset) = Codec::getResultDecode($data);
// 301, We can turn off this feature at server side
if ($_offset) {
$sleep += $sleep * 20;
$this->partitionList[] = array($partition, $sleep, $master, $partId);
$this->offset[$master] = $_offset;
$this->commitOffset($this->group, $master, $_offset, 0);
return array();
} else {
if ($offset) {
$this->partitionList[] = array($partition, $sleep, $master, $partId);
$this->offset[$master] += $offset;
$lastMsg = array_pop(array_values($msgs));
$lastId = $lastMsg['id'];
$this->commitOffset($this->group, $master, $this->offset[$master], $lastId);
if ($msgs) {
return $msgs;
}
} else {
$sleep += $sleep * 2;
$this->partitionList[] = array($partition, $sleep, $master, $partId);
// Reorder the partition list, sort and get the smallest sleep value
$parts = array_values($this->partitionList);
uasort($parts, array($this, 'cmp'));
$smallest = array_shift($parts);
if ($smallest[1] >= 2000000) {
//echo "sleep 2s\n";
//echo "offset ". $this->offset[$master]. "\n";
usleep(2000000);
foreach ($this->partitionList as $key => $value) {
$this->partitionList[$key][1] -= 2000000;
}
}
return array();
}
}
}