本文整理汇总了PHP中Thread::getCurrentThread方法的典型用法代码示例。如果您正苦于以下问题:PHP Thread::getCurrentThread方法的具体用法?PHP Thread::getCurrentThread怎么用?PHP Thread::getCurrentThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread::getCurrentThread方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
protected function send($message, $level, $prefix, $color)
{
$now = time();
$thread = \Thread::getCurrentThread();
if ($thread === null) {
$threadName = "Server thread";
} elseif ($thread instanceof Thread or $thread instanceof Worker) {
$threadName = $thread->getThreadName() . " thread";
} else {
$threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
}
$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s", $now) . "] " . TextFormat::RESET . $color . "[" . $prefix . "]:" . " " . $message . TextFormat::RESET);
//$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s") . "] ". TextFormat::RESET . $color ."<".$prefix . ">" . " " . $message . TextFormat::RESET);
$cleanMessage = TextFormat::clean($message);
if (!Terminal::hasFormattingCodes()) {
echo $cleanMessage . PHP_EOL;
} else {
echo $message . PHP_EOL;
}
if ($this->attachment instanceof \ThreadedLoggerAttachment) {
$this->attachment->call($level, $message);
}
$this->logStream[] = date("Y-m-d", $now) . " " . $cleanMessage . "\n";
if ($this->logStream->count() === 1) {
$this->synchronized(function () {
$this->notify();
});
}
}
示例2: send
protected function send($message, $level, $prefix, $color)
{
$now = time();
$thread = \Thread::getCurrentThread();
if ($thread === null) {
$threadName = "Server thread";
} elseif ($thread instanceof Thread or $thread instanceof Worker) {
$threadName = $thread->getThreadName() . " thread";
} else {
$threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
}
if ($this->shouldRecordMsg) {
if (time() - $this->lastGet >= 10) {
$this->shouldRecordMsg = false;
} else {
if (strlen($this->shouldSendMsg) >= 10000) {
$this->shouldSendMsg = "";
}
$this->shouldSendMsg .= $color . "|" . $prefix . "|" . trim($message, "\r\n") . "\n";
}
}
$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s", $now) . "] " . TextFormat::RESET . $color . "[" . $threadName . "/" . $prefix . "]:" . " " . $message . TextFormat::RESET);
//$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s") . "] ". TextFormat::RESET . $color ."<".$prefix . ">" . " " . $message . TextFormat::RESET);
$cleanMessage = TextFormat::clean($message);
if (!Terminal::hasFormattingCodes()) {
echo $cleanMessage . PHP_EOL;
} else {
echo $message . PHP_EOL;
}
if (isset($this->consoleCallback)) {
call_user_func($this->consoleCallback);
}
if ($this->attachment instanceof \ThreadedLoggerAttachment) {
$this->attachment->call($level, $message);
}
$this->logStream[] = date("Y-m-d", $now) . " " . $cleanMessage . "\n";
if ($this->logStream->count() === 1) {
$this->synchronized(function () {
$this->notify();
});
}
}