本文整理汇总了PHP中Entity::getTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::getTime方法的具体用法?PHP Entity::getTime怎么用?PHP Entity::getTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity::getTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postImpl
/**
* @param Entity $entity
* @return int
*/
protected function postImpl(Entity $entity)
{
/*
* example ouputs:
* 2012-02-26T01:26:20+0900 debug.test {"hello":"world"}
*/
$format = "%s\t%s\t%s\n";
return $this->write(sprintf($format, date(\DateTime::ISO8601, $entity->getTime()), $entity->getTag(), json_encode($entity->getData())));
}
示例2: postImpl
protected function postImpl(Entity $entity)
{
$packed = json_encode($entity->getData());
$data = $wbuffer = sprintf("%s\t%s\t%s", date(\DateTime::ISO8601, $entity->getTime()), $entity->getTag(), $packed . PHP_EOL);
$length = strlen($data);
$written = 0;
$retry = 0;
try {
if (!flock($this->fp, LOCK_EX)) {
throw new \Exception('could not obtain LOCK_EX');
}
fseek($this->fp, 0, SEEK_END);
while ($written < $length) {
$nwrite = fwrite($this->fp, $wbuffer);
if ($nwrite === false) {
throw new \Exception("could not write message");
} else {
if ($nwrite === "") {
throw new \Exception("connection aborted");
} else {
if ($nwrite === 0) {
if ($retry > self::MAX_WRITE_RETRY) {
throw new \Exception("failed fwrite retry: max retry count");
}
$retry++;
}
}
}
$written += $nwrite;
$wbuffer = substr($wbuffer, $written);
}
flock($this->fp, LOCK_UN);
} catch (\Exception $e) {
$this->processError($this, $entity, $e->getMessage());
return false;
}
return true;
}
示例3: pack
/**
* pack entity as a json string.
*
* @param Entity $entity
* @return string
*/
public function pack(Entity $entity)
{
return json_encode(array($entity->getTag(), $entity->getTime(), $entity->getData()));
}