|
|
|
<?php
|
|
|
|
namespace Jiaoyin;
|
|
|
|
//格式化输出
|
|
|
|
function output(){
|
|
|
|
use Swoole\Process;
|
|
|
|
|
|
|
|
function output(): void
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$outStr = '['.timeFormat('ms').']:';
|
|
|
|
foreach($args as $key => $value){
|
|
...
|
...
|
@@ -14,7 +17,8 @@ function output(){ |
|
|
|
echo $outStr.PHP_EOL;
|
|
|
|
}
|
|
|
|
//格式化时间
|
|
|
|
function timeFormat($type='s',$format='Y-m-d H:i:s'){
|
|
|
|
function timeFormat($type='s',$format='Y-m-d H:i:s'): string
|
|
|
|
{
|
|
|
|
date_default_timezone_set('Asia/Shanghai');
|
|
|
|
$microTime = microtime();
|
|
|
|
list($msTime,$sTime) = explode(' ',$microTime);
|
|
...
|
...
|
@@ -26,7 +30,7 @@ function timeFormat($type='s',$format='Y-m-d H:i:s'){ |
|
|
|
}
|
|
|
|
|
|
|
|
// 获取当前时间的微秒数
|
|
|
|
function getMicrotime()
|
|
|
|
function getMicrotime(): float|int
|
|
|
|
{
|
|
|
|
list($uSec, $sec) = explode(' ', microtime());
|
|
|
|
return $sec*1000+round($uSec*1000);
|
|
...
|
...
|
@@ -43,7 +47,8 @@ function getPrecision($number): int |
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getIntervalUnit($interval,$type='s'){
|
|
|
|
function getIntervalUnit($interval,$type='s'): float|int
|
|
|
|
{
|
|
|
|
$unitTime = 0;
|
|
|
|
if($interval == '1m'){
|
|
|
|
$unitTime = 60;
|
|
...
|
...
|
@@ -65,3 +70,17 @@ function getIntervalUnit($interval,$type='s'){ |
|
|
|
}
|
|
|
|
return $type == 's' ? $unitTime : $unitTime*1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
//以守护进程运行
|
|
|
|
function runAsDaemon($callback,$isDaemon=true): void
|
|
|
|
{
|
|
|
|
if($isDaemon){
|
|
|
|
Process::daemon();
|
|
|
|
$process = new Process(function ()use ($callback){
|
|
|
|
call_user_func($callback);
|
|
|
|
});
|
|
|
|
$process->start();
|
|
|
|
}else{
|
|
|
|
call_user_func($callback);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|