diff --git a/app/command/Dmtask.php b/app/command/Dmtask.php index f69eb53..d1f1aab 100644 --- a/app/command/Dmtask.php +++ b/app/command/Dmtask.php @@ -45,7 +45,7 @@ class Dmtask extends Command private function runtask() { - \Co::set(['hook_flags' => SWOOLE_HOOK_ALL]); + \Co::set(['hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_NATIVE_CURL]); \Co\run(function () { $date = date("Ymd"); $count = config_get('run_count', null, true) ?? 0; diff --git a/app/lib/NewDbManager.php b/app/lib/NewDbManager.php index eb568b9..6e2d578 100644 --- a/app/lib/NewDbManager.php +++ b/app/lib/NewDbManager.php @@ -10,11 +10,11 @@ class NewDbManager extends \think\Db /** * 创建数据库连接实例 * @access protected - * @param string|null $name 连接标识 + * @param string|array|null $name 连接标识 * @param bool $force 强制重新连接 * @return ConnectionInterface */ - protected function instance(string $name = null, bool $force = false): ConnectionInterface + protected function instance(string|array $name = null, bool $force = false): ConnectionInterface { if (empty($name)) { $name = $this->getConfig('default', 'mysql'); diff --git a/app/utils/CheckUtils.php b/app/utils/CheckUtils.php index aa684d8..523b378 100644 --- a/app/utils/CheckUtils.php +++ b/app/utils/CheckUtils.php @@ -12,17 +12,12 @@ class CheckUtils if (!$urlarr) { return ['status' => false, 'errmsg' => 'Invalid URL', 'usetime' => 0]; } - if (substr($urlarr['host'], 0, 1) == '[' && substr($urlarr['host'], -1) == ']') { - $urlarr['host'] = substr($urlarr['host'], 1, -1); - } - if (!empty($ip) && !filter_var($urlarr['host'], FILTER_VALIDATE_IP)) { - if (!filter_var($ip, FILTER_VALIDATE_IP)) { - $ip = gethostbyname($ip); - } - if (!empty($ip) && filter_var($ip, FILTER_VALIDATE_IP)) { - $port = isset($urlarr['port']) ? $urlarr['port'] : ($urlarr['scheme'] == 'https' ? 443 : 80); - $resolve = $urlarr['host'] . ':' . $port . ':' . $ip; - } + if (str_starts_with($urlarr['host'], '[') && str_ends_with($urlarr['host'], ']')) { + $urlarr['host'] = substr($urlarr['host'], 1, -1); + } + if (!empty($ip) && !filter_var($urlarr['host'], FILTER_VALIDATE_IP) && filter_var($ip, FILTER_VALIDATE_IP)) { + $port = $urlarr['port'] ?? ($urlarr['scheme'] == 'https' ? 443 : 80); + $resolve = $urlarr['host'] . ':' . $port . ':' . $ip; } $ch = curl_init(); if ($proxy) { @@ -83,12 +78,12 @@ class CheckUtils public static function tcp($target, $ip, $port, $timeout) { if (!empty($ip) && filter_var($ip, FILTER_VALIDATE_IP)) $target = $ip; - if (substr($target, -1) == '.') $target = substr($target, 0, -1); + if (str_ends_with($target, '.')) $target = substr($target, 0, -1); if (!filter_var($target, FILTER_VALIDATE_IP) && checkDomain($target)) { $target = gethostbyname($target); if (!$target) return ['status' => false, 'errmsg' => 'DNS resolve failed', 'usetime' => 0]; } - if (filter_var($target, FILTER_VALIDATE_IP) && strpos($target, ':') !== false) { + if (filter_var($target, FILTER_VALIDATE_IP) && str_contains($target, ':')) { $target = '['.$target.']'; } $starttime = getMillisecond(); @@ -108,7 +103,7 @@ class CheckUtils { if (!function_exists('exec')) return ['status' => false, 'errmsg' => 'exec函数不可用', 'usetime' => 0]; if (!empty($ip) && filter_var($ip, FILTER_VALIDATE_IP)) $target = $ip; - if (substr($target, -1) == '.') $target = substr($target, 0, -1); + if (str_ends_with($target, '.')) $target = substr($target, 0, -1); if (!filter_var($target, FILTER_VALIDATE_IP) && checkDomain($target)) { $target = gethostbyname($target); if (!$target) return ['status' => false, 'errmsg' => 'DNS resolve failed', 'usetime' => 0]; @@ -117,7 +112,7 @@ class CheckUtils return ['status' => false, 'errmsg' => 'Invalid IP address', 'usetime' => 0]; } $timeout = 1; - exec('ping -c 1 -w '.$timeout.' '.$target.'', $output, $return_var); + exec('ping -c 1 -w '.$timeout.' '.$target, $output, $return_var); $usetime = !empty($output[1]) ? round(getSubstr($output[1], 'time=', ' ms')) : 0; $errmsg = null; if ($return_var !== 0) {