BiliHelper-personal/src/util/TimeLock.php
alfred cf379002a4 Use socket_select to improve socket reader efficiency
Fix:(When using ZoneTcpClient)
1. Many packets are stuck in receiving queue, cannot be processed in time;
   On Linux, use below command to check Recv-Q:
       ss -ntp dport = 2243
2. Above issue will cause websocket to be dropped from time to time.
3. Improve websocket message parsing, so we won't see unexpected messages;
2020-03-20 22:22:35 +08:00

58 lines
957 B
PHP

<?php
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2020 ~ 2021
*/
namespace BiliHelper\Util;
use Amp\Delayed;
trait TimeLock
{
public static $lock = 0;
/**
* @use 设置时间
* @param int $lock
*/
public static function setLock(int $lock)
{
static::$lock = time() + $lock;
}
/**
* @use 获取时间
* @return int
*/
public static function getLock(): int
{
return static::$lock;
}
/**
* @use used in Amp loop Delayed
* @return delayed
*/
public static function Delayed()
{
return new Delayed(1000);
}
/**
* @use 定时
* @param int $hour
* @return int
*/
public static function timing(int $hour): int
{
// now today tomorrow yesterday
return strtotime('tomorrow') + ($hour * 60 * 60) - time();
}
}