作者 zed

删除多余文件functions

1 <?php 1 <?php
2 2
3 -namespace jiaoyin; 3 +namespace Jiaoyin;
4 //格式化输出 4 //格式化输出
5 use Swoole\Process; 5 use Swoole\Process;
6 use Swoole\Event; 6 use Swoole\Event;
1 -<?php  
2 -namespace Jiaoyin;  
3 -//格式化输出  
4 -use Swoole\Process;  
5 -use Swoole\Event;  
6 -  
7 -function output(): void  
8 -{  
9 - $args = func_get_args();  
10 - $outStr = '['.timeFormat('ms').']:';  
11 - foreach($args as $key => $value){  
12 - $value = is_array($value) ? json_encode($value) : $value;  
13 - if(is_bool($value)){  
14 - $value = $value ? 'bool:true':'bool:false';  
15 - }  
16 - $outStr .= count($args) - $key > 1 ? $value.' ' : $value;  
17 - }  
18 - echo $outStr.PHP_EOL;  
19 -}  
20 -//格式化时间  
21 -function timeFormat($type='s',$format='Y-m-d H:i:s'): string  
22 -{  
23 - date_default_timezone_set('Asia/Shanghai');  
24 - $microTime = microtime();  
25 - list($msTime,$sTime) = explode(' ',$microTime);  
26 - $timeStr = date($format,$sTime);  
27 - if($type == 'ms'){  
28 - $timeStr .= '.'.sprintf("%03d",floor($msTime*1000));  
29 - }  
30 - return $timeStr;  
31 -}  
32 -  
33 -// 获取当前时间的微秒数  
34 -function getMicrotime(): float|int  
35 -{  
36 - list($uSec, $sec) = explode(' ', microtime());  
37 - return $sec*1000+round($uSec*1000);  
38 -}  
39 -  
40 -//获取精度  
41 -function getPrecision($number): int  
42 -{  
43 - $count = 0;  
44 - while($number < 1){  
45 - $number *= 10;  
46 - $count += 1;  
47 - }  
48 - return $count;  
49 -}  
50 -  
51 -function getIntervalUnit($interval,$type='s'): float|int  
52 -{  
53 - $unitTime = 0;  
54 - if($interval == '1m'){  
55 - $unitTime = 60;  
56 - }  
57 - if($interval == '5m'){  
58 - $unitTime = 60*5;  
59 - }  
60 - if($interval == '15m'){  
61 - $unitTime = 60*15;  
62 - }  
63 - if($interval == '1h'){  
64 - $unitTime = 60*60;  
65 - }  
66 - if($interval == '4h'){  
67 - $unitTime = 60*60*4;  
68 - }  
69 - if($interval == '1d'){  
70 - $unitTime = 60*60*24;  
71 - }  
72 - return $type == 's' ? $unitTime : $unitTime*1000;  
73 -}  
74 -  
75 -//以守护进程运行  
76 -function runAsDaemon($callback,$isDaemon=true): void  
77 -{  
78 - if($isDaemon){  
79 - Process::daemon();  
80 - $process = new Process(function ()use ($callback){  
81 - call_user_func($callback);  
82 - Event::wait();  
83 - });  
84 - $process->start();  
85 - }else{  
86 - call_user_func($callback);  
87 - Event::wait();  
88 - }  
89 -}