82 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2024-09-29 15:43:18 +08:00
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\index\controller;
use think\admin\Controller;
2024-12-04 12:33:47 +08:00
use think\exception\HttpResponseException;
2024-09-29 15:43:18 +08:00
class Index extends Controller
{
public function index()
{
2024-12-04 12:33:47 +08:00
return response('Hello, Swoole!');
throw new HttpResponseException(json($_SERVER));die;
$environment = $this->detectEnvironment();
switch ($environment) {
case 'swoole':
return "当前运行在 Swoole 下";
break;
case 'workerman':
return "当前运行在 Workerman 下";
break;
default:
return "当前运行在其他环境中";
break;
}
return response(json($_SERVER));die;
print_r('error');
2024-09-29 15:43:18 +08:00
// $this->redirect(sysuri('admin/login/index'));
2024-09-29 15:43:18 +08:00
}
2024-12-04 12:33:47 +08:00
function detectEnvironment(): string
{
if (defined('SWOOLE_VERSION')) {
return 'swoole';
}
if (class_exists(\swoole_http_server::class)) {
return 'swoole';
}
if (defined('WORKERMAN_VERSION')) {
return 'workerman';
}
if (class_exists(\Worker::class)) {
return 'workerman';
}
$serverSoftware = $_SERVER['SERVER_SOFTWARE'] ?? '';
if (strpos($serverSoftware, 'swoole') !== false) {
return 'swoole';
}
if (strpos($serverSoftware, 'workerman') !== false) {
return 'workerman';
}
return 'other'; // 默认返回其他环境
}
2024-09-29 15:43:18 +08:00
}