|
|
<?php
|
|
|
|
|
|
namespace Lib;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 这个是协程封装
|
|
|
* @author:dc
|
|
|
* @time 2025/3/17 11:22
|
|
|
* Class SwGo
|
|
|
* @package Lib
|
|
|
*/
|
|
|
class SwGo {
|
|
|
|
|
|
/**
|
|
|
* 运行状态
|
|
|
* @var array
|
|
|
*/
|
|
|
public static $runStatus = [];
|
|
|
|
|
|
/**
|
|
|
* 已经运行的go数量
|
|
|
* @var int
|
|
|
*/
|
|
|
public static $runNumber = 0;
|
|
|
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param \Closure $run
|
|
|
* @param \Closure $end
|
|
|
* @author:dc
|
|
|
* @time 2025/3/17 11:35
|
|
|
*/
|
|
|
public static function start(\Closure $run,...$param): bool
|
|
|
{
|
|
|
|
|
|
go(function (\Closure $run,...$param){
|
|
|
self::$runNumber++;
|
|
|
|
|
|
$run(...$param);
|
|
|
|
|
|
// 写入日志
|
|
|
\Lib\Log::getInstance()->write();
|
|
|
// 释放 mysql
|
|
|
db()->close();
|
|
|
// 释放redis
|
|
|
redis()->close();
|
|
|
|
|
|
self::$runNumber--;
|
|
|
|
|
|
},$run,...$param);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|