82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?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;
|
||
use think\exception\HttpResponseException;
|
||
|
||
class Index extends Controller
|
||
{
|
||
public function index()
|
||
{
|
||
|
||
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');
|
||
|
||
// $this->redirect(sysuri('admin/login/index'));
|
||
}
|
||
|
||
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'; // 默认返回其他环境
|
||
}
|
||
|
||
|
||
} |