diff --git a/.gitignore b/.gitignore index 5054a67..5bf29bb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ Thumbs.db /vendor /.settings /.buildpath -/.project \ No newline at end of file +/.project +/public/upload/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..143ad1f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM php:8.2.16-cli-alpine3.19 + +CMD ["php", "-f", "/var/www/html/start.php"] \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..3dcd79f --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,32 @@ + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 +版权所有Copyright © 2006-2023 by ThinkPHP (http://thinkphp.cn) +All rights reserved。 +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +Apache Licence是著名的非盈利开源组织Apache采用的协议。 +该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, +允许代码修改,再作为开源或商业软件发布。需要满足 +的条件: +1. 需要给代码的用户一份Apache Licence ; +2. 如果你修改了代码,需要在被修改的文件中说明; +3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 +带有原来代码中的协议,商标,专利声明和其他原来作者规 +定需要包含的说明; +4. 如果再发布的产品中包含一个Notice文件,则在Notice文 +件中需要带有本协议内容。你可以在Notice中增加自己的 +许可,但不可以表现为对Apache Licence构成更改。 +具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d1e7881 --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +![](https://www.thinkphp.cn/uploads/images/20230630/300c856765af4d8ae758c503185f8739.png) + +ThinkPHP 8.0 +=============== + +## 特性 + +* 基于PHP`8.0+`重构 +* 升级`PSR`依赖 +* 依赖`think-orm`3.0版本 +* `6.0`/`6.1`无缝升级 + + +> ThinkPHP8.0的运行环境要求PHP8.0.0+ + +现在开始,你可以使用官方提供的[ThinkChat](https://chat.topthink.com/),让你在学习ThinkPHP的旅途中享受私人AI助理服务! + +![](https://www.topthink.com/uploads/assistant/20230630/4d1a3f0ad2958b49bb8189b7ef824cb0.png) + +## 文档 + +[完全开发手册](https://doc.thinkphp.cn) + +## 服务 + +ThinkPHP生态服务由[顶想云](https://www.topthink.com)(TOPThink Cloud)提供,为生态提供专业的开发者服务和价值之选。 + +## 赞助 +全新的[赞助计划](https://www.thinkphp.cn/sponsor)可以让你通过我们的网站、手册、欢迎页及GIT仓库获得巨大曝光,同时提升企业的品牌声誉,也更好保障ThinkPHP的可持续发展。 + +[![](https://www.thinkphp.cn/uploads/images/20230630/48396092a0515886a3da6bd268131c8f.png)](http://github.crmeb.net/u/TPSY) + +[![](https://www.thinkphp.cn/uploads/images/20230630/a12bd248beee0e7491dd0f79dc4dd5e9.png)](https://www.thinkphp.cn/sponsor) + +[![](https://www.thinkphp.cn/uploads/images/20230630/e7f48d909d41dd5ebaf4a5aa982d0455.png)](https://www.thinkphp.cn/sponsor) + +## 安装 + +~~~ +composer create-project topthink/think tp +~~~ + +启动服务 + +~~~ +cd tp +php think run +~~~ + +然后就可以在浏览器中访问 + +~~~ +http://localhost:8000 +~~~ + +如果需要更新框架使用 +~~~ +composer update topthink/framework +~~~ + +## 命名规范 + +`ThinkPHP`遵循PSR-2命名规范和PSR-4自动加载规范。 + +## 参与开发 + +直接提交PR或者Issue即可 + +## 版权信息 + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 + +本项目包含的第三方源码和二进制文件之版权信息另行标注。 + +版权所有Copyright © 2006-2023 by ThinkPHP (http://thinkphp.cn) All rights reserved。 + +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +更多细节参阅 [LICENSE.txt](LICENSE.txt) diff --git a/app/common.php b/app/common.php new file mode 100644 index 0000000..57cb6d8 --- /dev/null +++ b/app/common.php @@ -0,0 +1,2 @@ + 200, + 'msg' => 'success', + 'data' => [ + 'name' => 'thinkphp6' + ] + ]); + } + + public function upload() + { + $file = request()->file('file'); + $trueName = $file->getOriginalName(); + + $serverIP = env('SERVER_ADDR', '192.168.1.161'); + $serverPort = env('SERVER_PORT', 8000); + + // 组装保存路径 + $savename = \think\facade\Filesystem::disk('upload')->putFile('upload', $file); + $savename = str_replace('\\', '/', $savename); + + return json([ + 'code' => 200, + 'msg' => null, + 'data' => [ + "name" => $trueName, + "url" => 'http://' . $serverIP . ':' . $serverPort . '/' . $savename, + // "url" => 'http://192.168.1.105:8080/file/' . $savename, + ] + ]); + } +} diff --git a/app/middleware.php b/app/middleware.php new file mode 100644 index 0000000..d2c3fda --- /dev/null +++ b/app/middleware.php @@ -0,0 +1,10 @@ +=8.0.0", + "topthink/framework": "^8.0", + "topthink/think-orm": "^3.0", + "topthink/think-filesystem": "^2.0", + "guzzlehttp/guzzle": "^7.9", + "topthink/think-worker": "^4.0" + }, + "require-dev": { + "symfony/var-dumper": ">=4.2", + "topthink/think-trace": "^1.0" + }, + "autoload": { + "psr-4": { + "app\\": "app" + } + }, + "config": { + "preferred-install": "dist" + }, + "scripts": { + "post-autoload-dump": [ + "@php think service:discover", + "@php think vendor:publish" + ] + } +} diff --git a/config/app.php b/config/app.php new file mode 100644 index 0000000..8cb245c --- /dev/null +++ b/config/app.php @@ -0,0 +1,32 @@ + env('APP_HOST', ''), + // 应用的命名空间 + 'app_namespace' => '', + // 是否启用路由 + 'with_route' => true, + // 默认应用 + 'default_app' => 'index', + // 默认时区 + 'default_timezone' => 'Asia/Shanghai', + + // 应用映射(自动多应用模式有效) + 'app_map' => [], + // 域名绑定(自动多应用模式有效) + 'domain_bind' => [], + // 禁止URL访问的应用列表(自动多应用模式有效) + 'deny_app_list' => [], + + // 异常页面的模板文件 + 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', + + // 错误显示信息,非调试模式有效 + 'error_message' => '页面错误!请稍后再试~', + // 显示错误信息 + 'show_error_msg' => false, +]; diff --git a/config/cache.php b/config/cache.php new file mode 100644 index 0000000..6b72dc8 --- /dev/null +++ b/config/cache.php @@ -0,0 +1,29 @@ + 'file', + + // 缓存连接方式配置 + 'stores' => [ + 'file' => [ + // 驱动方式 + 'type' => 'File', + // 缓存保存目录 + 'path' => '', + // 缓存前缀 + 'prefix' => '', + // 缓存有效期 0表示永久缓存 + 'expire' => 0, + // 缓存标签前缀 + 'tag_prefix' => 'tag:', + // 序列化机制 例如 ['serialize', 'unserialize'] + 'serialize' => [], + ], + // 更多的缓存连接 + ], +]; diff --git a/config/console.php b/config/console.php new file mode 100644 index 0000000..a818a98 --- /dev/null +++ b/config/console.php @@ -0,0 +1,9 @@ + [ + ], +]; diff --git a/config/cookie.php b/config/cookie.php new file mode 100644 index 0000000..d3b3aab --- /dev/null +++ b/config/cookie.php @@ -0,0 +1,20 @@ + 0, + // cookie 保存路径 + 'path' => '/', + // cookie 有效域名 + 'domain' => '', + // cookie 启用安全传输 + 'secure' => false, + // httponly设置 + 'httponly' => false, + // 是否使用 setcookie + 'setcookie' => true, + // samesite 设置,支持 'strict' 'lax' + 'samesite' => '', +]; diff --git a/config/database.php b/config/database.php new file mode 100644 index 0000000..bd5ab81 --- /dev/null +++ b/config/database.php @@ -0,0 +1,63 @@ + env('DB_DRIVER', 'mysql'), + + // 自定义时间查询规则 + 'time_query_rule' => [], + + // 自动写入时间戳字段 + // true为自动识别类型 false关闭 + // 字符串则明确指定时间字段类型 支持 int timestamp datetime date + 'auto_timestamp' => true, + + // 时间字段取出后的默认时间格式 + 'datetime_format' => 'Y-m-d H:i:s', + + // 时间字段配置 配置格式:create_time,update_time + 'datetime_field' => '', + + // 数据库连接配置信息 + 'connections' => [ + 'mysql' => [ + // 数据库类型 + 'type' => env('DB_TYPE', 'mysql'), + // 服务器地址 + 'hostname' => env('DB_HOST', '127.0.0.1'), + // 数据库名 + 'database' => env('DB_NAME', ''), + // 用户名 + 'username' => env('DB_USER', 'root'), + // 密码 + 'password' => env('DB_PASS', ''), + // 端口 + 'hostport' => env('DB_PORT', '3306'), + // 数据库连接参数 + 'params' => [], + // 数据库编码默认采用utf8 + 'charset' => env('DB_CHARSET', 'utf8'), + // 数据库表前缀 + 'prefix' => env('DB_PREFIX', ''), + + // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'deploy' => 0, + // 数据库读写是否分离 主从式有效 + 'rw_separate' => false, + // 读写分离后 主服务器数量 + 'master_num' => 1, + // 指定从服务器序号 + 'slave_no' => '', + // 是否严格检查字段是否存在 + 'fields_strict' => true, + // 是否需要断线重连 + 'break_reconnect' => false, + // 监听SQL + 'trigger_sql' => env('APP_DEBUG', true), + // 开启字段缓存 + 'fields_cache' => false, + ], + + // 更多的数据库配置信息 + ], +]; diff --git a/config/filesystem.php b/config/filesystem.php new file mode 100644 index 0000000..e91f808 --- /dev/null +++ b/config/filesystem.php @@ -0,0 +1,34 @@ + 'local', + // 磁盘列表 + 'disks' => [ + 'local' => [ + 'type' => 'local', + 'root' => app()->getRuntimePath() . 'storage', + ], + 'public' => [ + // 磁盘类型 + 'type' => 'local', + // 磁盘路径 + 'root' => app()->getRootPath() . 'public/storage', + // 磁盘路径对应的外部URL路径 + 'url' => '/storage', + // 可见性 + 'visibility' => 'public', + ], + // 更多的磁盘配置信息 + 'upload' => [ + // 磁盘类型 + 'type' => 'local', + // 磁盘路径 + 'root' => app()->getRootPath() . 'public', + // 磁盘路径对应的外部URL路径 + 'url' => '/uploads', + // 可见性 + 'visibility' => 'public', + ] + ], +]; diff --git a/config/gateway_worker.php b/config/gateway_worker.php new file mode 100644 index 0000000..21d1ebe --- /dev/null +++ b/config/gateway_worker.php @@ -0,0 +1,45 @@ + +// +---------------------------------------------------------------------- +// +---------------------------------------------------------------------- +// | Workerman设置 仅对 php think worker:gateway 指令有效 +// +---------------------------------------------------------------------- +return [ + // 扩展自身需要的配置 + 'protocol' => 'websocket', // 协议 支持 tcp udp unix http websocket text + 'host' => '0.0.0.0', // 监听地址 + 'port' => 2348, // 监听端口 + 'socket' => '', // 完整监听地址 + 'context' => [], // socket 上下文选项 + 'register_deploy' => true, // 是否需要部署register + 'businessWorker_deploy' => true, // 是否需要部署businessWorker + 'gateway_deploy' => true, // 是否需要部署gateway + + // Register配置 + 'registerAddress' => '127.0.0.1:1236', + + // Gateway配置 + 'name' => 'thinkphp', + 'count' => 1, + 'lanIp' => '127.0.0.1', + 'startPort' => 2000, + 'daemonize' => false, + 'pingInterval' => 30, + 'pingNotResponseLimit' => 0, + 'pingData' => '{"type":"ping"}', + + // BusinsessWorker配置 + 'businessWorker' => [ + 'name' => 'BusinessWorker', + 'count' => 1, + 'eventHandler' => '\think\worker\Events', + ], + +]; diff --git a/config/lang.php b/config/lang.php new file mode 100644 index 0000000..0d8b693 --- /dev/null +++ b/config/lang.php @@ -0,0 +1,27 @@ + env('DEFAULT_LANG', 'zh-cn'), + // 允许的语言列表 + 'allow_lang_list' => [], + // 多语言自动侦测变量名 + 'detect_var' => 'lang', + // 是否使用Cookie记录 + 'use_cookie' => true, + // 多语言cookie变量 + 'cookie_var' => 'think_lang', + // 多语言header变量 + 'header_var' => 'think-lang', + // 扩展语言包 + 'extend_list' => [], + // Accept-Language转义为对应语言包名称 + 'accept_language' => [ + 'zh-hans-cn' => 'zh-cn', + ], + // 是否支持语言分组 + 'allow_group' => false, +]; diff --git a/config/log.php b/config/log.php new file mode 100644 index 0000000..0d406f8 --- /dev/null +++ b/config/log.php @@ -0,0 +1,45 @@ + 'file', + // 日志记录级别 + 'level' => [], + // 日志类型记录的通道 ['error'=>'email',...] + 'type_channel' => [], + // 关闭全局日志写入 + 'close' => false, + // 全局日志处理 支持闭包 + 'processor' => null, + + // 日志通道列表 + 'channels' => [ + 'file' => [ + // 日志记录方式 + 'type' => 'File', + // 日志保存目录 + 'path' => '', + // 单文件日志写入 + 'single' => false, + // 独立日志级别 + 'apart_level' => [], + // 最大日志文件数量 + 'max_files' => 0, + // 使用JSON格式记录 + 'json' => false, + // 日志处理 + 'processor' => null, + // 关闭通道日志写入 + 'close' => false, + // 日志输出格式化 + 'format' => '[%s][%s] %s', + // 是否实时写入 + 'realtime_write' => false, + ], + // 其它日志通道配置 + ], + +]; diff --git a/config/middleware.php b/config/middleware.php new file mode 100644 index 0000000..7e1972f --- /dev/null +++ b/config/middleware.php @@ -0,0 +1,8 @@ + [], + // 优先级设置,此数组中的中间件会按照数组中的顺序优先执行 + 'priority' => [], +]; diff --git a/config/route.php b/config/route.php new file mode 100644 index 0000000..2f4cd12 --- /dev/null +++ b/config/route.php @@ -0,0 +1,45 @@ + '/', + // URL伪静态后缀 + 'url_html_suffix' => 'html', + // URL普通方式参数 用于自动生成 + 'url_common_param' => true, + // 是否开启路由延迟解析 + 'url_lazy_route' => false, + // 是否强制使用路由 + 'url_route_must' => false, + // 合并路由规则 + 'route_rule_merge' => false, + // 路由是否完全匹配 + 'route_complete_match' => false, + // 访问控制器层名称 + 'controller_layer' => 'controller', + // 空控制器名 + 'empty_controller' => 'Error', + // 是否使用控制器后缀 + 'controller_suffix' => false, + // 默认的路由变量规则 + 'default_route_pattern' => '[\w\.]+', + // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则 + 'request_cache_key' => false, + // 请求缓存有效期 + 'request_cache_expire' => null, + // 全局请求缓存排除规则 + 'request_cache_except' => [], + // 默认控制器名 + 'default_controller' => 'Index', + // 默认操作名 + 'default_action' => 'index', + // 操作方法后缀 + 'action_suffix' => '', + // 默认JSONP格式返回的处理方法 + 'default_jsonp_handler' => 'jsonpReturn', + // 默认JSONP处理方法 + 'var_jsonp_handler' => 'callback', +]; diff --git a/config/session.php b/config/session.php new file mode 100644 index 0000000..c1ef6e1 --- /dev/null +++ b/config/session.php @@ -0,0 +1,19 @@ + 'PHPSESSID', + // SESSION_ID的提交变量,解决flash上传跨域 + 'var_session_id' => '', + // 驱动方式 支持file cache + 'type' => 'file', + // 存储连接标识 当type使用cache的时候有效 + 'store' => null, + // 过期时间 + 'expire' => 1440, + // 前缀 + 'prefix' => '', +]; diff --git a/config/trace.php b/config/trace.php new file mode 100644 index 0000000..fad2392 --- /dev/null +++ b/config/trace.php @@ -0,0 +1,10 @@ + 'Html', + // 读取的日志通道名 + 'channel' => '', +]; diff --git a/config/view.php b/config/view.php new file mode 100644 index 0000000..01259a0 --- /dev/null +++ b/config/view.php @@ -0,0 +1,25 @@ + 'Think', + // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法 + 'auto_rule' => 1, + // 模板目录名 + 'view_dir_name' => 'view', + // 模板后缀 + 'view_suffix' => 'html', + // 模板文件名分隔符 + 'view_depr' => DIRECTORY_SEPARATOR, + // 模板引擎普通标签开始标记 + 'tpl_begin' => '{', + // 模板引擎普通标签结束标记 + 'tpl_end' => '}', + // 标签库标签开始标记 + 'taglib_begin' => '{', + // 标签库标签结束标记 + 'taglib_end' => '}', +]; diff --git a/config/worker.php b/config/worker.php new file mode 100644 index 0000000..38155fd --- /dev/null +++ b/config/worker.php @@ -0,0 +1,77 @@ + +// +---------------------------------------------------------------------- + +// +---------------------------------------------------------------------- +// | Workerman设置 仅对 php think worker 指令有效 +// +---------------------------------------------------------------------- + +use GuzzleHttp\Client; +use think\facade\Log; +use Workerman\Worker; +use Workerman\Lib\Timer; + +return [ + // 扩展自身需要的配置 + 'host' => '0.0.0.0', // 监听地址 + 'port' => 2346, // 监听端口 + 'root' => '', // WEB 根目录 默认会定位public目录 + 'app_path' => '', // 应用目录 守护进程模式必须设置(绝对路径) + 'file_monitor' => false, // 是否开启PHP文件更改监控(调试模式下自动开启) + 'file_monitor_interval' => 2, // 文件监控检测时间间隔(秒) + 'file_monitor_path' => [], // 文件监控目录 默认监控application和config目录 + + // 支持workerman的所有配置参数 + 'name' => 'thinkphp', + 'count' => 1, + 'daemonize' => false, + 'pidFile' => '', + 'onWorkerStart' => function($worker) { + $task = new Worker(); + $task->count = 1; + $task->onWorkerStart = function(Worker $task) { + // 获取本地IP + $serverIP = env('SERVER_ADDR', '192.168.1.161'); + $serverPort = env('SERVER_PORT', 2346); + // 控制台输出 + Log::record('workerman start'); + Log::record('Workerman config:' . $serverIP . ':' . $serverPort, 'info'); + $client = new Client([ + // nacos地址 + "base_uri" => "http://192.168.1.105:8848", + "timeout" => 5 + ]); + // 每2.5秒执行一次 + Timer::add(5, function() use ($client, $serverIP, $serverPort) + { + $response = $client->request("put", "/nacos/v1/ns/instance/beat", [ + "form_params" => [ + "serviceName" => "zeroerroa-file", + "ip" => $serverIP, + "port" => $serverPort, + "namespaceId" => "0a1c32f2-dea1-4ec1-b546-cb4635cd7db2", + "groupName" => "DEFAULT_GROUP", + "beat" => '{ + "cluster": "DEFAULT", + "ip": "' . $serverIP . '", + "metadata": {}, + "port": "' . $serverPort . '", + "scheduled": true, + "serviceName": "zeroerroa-file", + "weight": 1 + }' + ], + ]); + echo "send heartbeat: " . $response->getBody()->getContents(); + echo "\n"; + }); + }; + } +]; diff --git a/config/worker_server.php b/config/worker_server.php new file mode 100644 index 0000000..2ecbac1 --- /dev/null +++ b/config/worker_server.php @@ -0,0 +1,59 @@ + +// +---------------------------------------------------------------------- + +// +---------------------------------------------------------------------- +// | Workerman设置 仅对 php think worker:server 指令有效 +// +---------------------------------------------------------------------- + +use think\facade\Log; + +return [ + // 扩展自身需要的配置 + 'protocol' => 'websocket', // 协议 支持 tcp udp unix http websocket text + 'host' => '0.0.0.0', // 监听地址 + 'port' => 2345, // 监听端口 + 'socket' => '', // 完整监听地址 + 'context' => [], // socket 上下文选项 + 'worker_class' => '', // 自定义Workerman服务类名 支持数组定义多个服务 + + // 支持workerman的所有配置参数 + 'name' => 'thinkphp', + 'count' => 4, + 'daemonize' => false, + 'pidFile' => '', + + // 支持事件回调 + // onWorkerStart + 'onWorkerStart' => function ($worker) { + // 添加新线程 + // Log::info('WorkerStart'); + }, + // onWorkerReload + 'onWorkerReload' => function ($worker) { + + }, + // onConnect + 'onConnect' => function ($connection) { + + }, + // onMessage + 'onMessage' => function ($connection, $data) { + $connection->send('receive success'); + }, + // onClose + 'onClose' => function ($connection) { + + }, + // onError + 'onError' => function ($connection, $code, $msg) { + echo "error [ $code ] $msg\n"; + }, +]; diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..cbc7868 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,8 @@ + + Options +FollowSymlinks -Multiviews + RewriteEngine On + + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..3f2817f Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..e3c0fe9 --- /dev/null +++ b/public/index.php @@ -0,0 +1,24 @@ + +// +---------------------------------------------------------------------- + +// [ 应用入口文件 ] +namespace think; + +require __DIR__ . '/../vendor/autoload.php'; + +// 执行HTTP应用并响应 +$http = (new App())->http; + +$response = $http->run(); + +$response->send(); + +$http->end($response); diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..eb05362 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/public/router.php b/public/router.php new file mode 100644 index 0000000..9b39a62 --- /dev/null +++ b/public/router.php @@ -0,0 +1,19 @@ + +// +---------------------------------------------------------------------- +// $Id$ + +if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) { + return false; +} else { + $_SERVER["SCRIPT_FILENAME"] = __DIR__ . '/index.php'; + + require __DIR__ . "/index.php"; +} diff --git a/public/static/.gitignore b/public/static/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/public/static/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/route/app.php b/route/app.php new file mode 100644 index 0000000..34e5371 --- /dev/null +++ b/route/app.php @@ -0,0 +1,23 @@ + +// +---------------------------------------------------------------------- +use think\facade\Route; + +// 文件上传 +Route::post('/file/upload', 'index/upload'); +Route::post('/upload', 'index/upload'); + +Route::get('/actuator/health', function () { + return 'hello,ThinkPHP6!'; +}); + +Route::get('/actuator/info', function () { + return 'hello,ThinkPHP6!'; +}); diff --git a/runtime/.gitignore b/runtime/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/runtime/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/start.php b/start.php new file mode 100644 index 0000000..a771caf --- /dev/null +++ b/start.php @@ -0,0 +1,56 @@ +load(__DIR__ . '/.env'); +$serverIP = $env->get('SERVER_ADDR', '192.168.1.161'); +$serverPort = $env->get('SERVER_PORT', 8000); + +$task = new Worker(); + +// 定时触发邮件发送任务 +// 开启多少个进程运行定时任务,注意业务是否在多进程有并发问题 +$task->count = 1; +$task->onWorkerStart = function(Worker $task) use ($serverIP, $serverPort) +{ + $client = new Client([ + // nacos地址 + "base_uri" => "http://192.168.1.105:8848", + "timeout" => 5 + ]); + // 每2.5秒执行一次 + Timer::add(5, function() use ($client, $serverIP, $serverPort) + { + $response = $client->request("put", "/nacos/v1/ns/instance/beat", [ + "form_params" => [ + "serviceName" => "zeroerroa-file", + "ip" => $serverIP, + "port" => $serverPort, + "namespaceId" => "0a1c32f2-dea1-4ec1-b546-cb4635cd7db2", + "groupName" => "DEFAULT_GROUP", + "beat" => '{ + "cluster": "DEFAULT", + "ip": "' . $serverIP . '", + "metadata": {}, + "port": "' . $serverPort . '", + "scheduled": true, + "serviceName": "zeroerroa-file", + "weight": 1 + }' + ], + ]); + echo "send heartbeat: " . $response->getBody()->getContents(); + echo "\n"; + }); +}; + +// 运行worker +Worker::runAll(); \ No newline at end of file diff --git a/think b/think new file mode 100644 index 0000000..2429d22 --- /dev/null +++ b/think @@ -0,0 +1,10 @@ +#!/usr/bin/env php +console->run(); \ No newline at end of file diff --git a/view/README.md b/view/README.md new file mode 100644 index 0000000..360eb24 --- /dev/null +++ b/view/README.md @@ -0,0 +1 @@ +如果不使用模板,可以删除该目录 \ No newline at end of file