diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..30692b3 --- /dev/null +++ b/.env.example @@ -0,0 +1,41 @@ +# 开启DEBUG时,客户端会看到详细的异常信息 +DEBUG = true + +# 主服务配置 +SERVER_NAME = webman-jsonrpc +SERVER_LISTEN = http://0.0.0.0:7878 +SERVER_COUNT = cpu_count() +MAX_PACKAGE_SIZE = 1024*1024*5 + +# REDIS配置 +REDIS_HOST = 127.0.0.1 +REDIS_PORT = 6379 +REDIS_PASSWORD = null +REDIS_DATABASE = 0 + +# 数据库 +DB_DEFAULT_DRIVER = pgsql + +# mysql +MYSQL_HOST = 127.0.0.1 +MYSQL_PORT = 3306 +MYSQL_USERNAME = +MYSQL_PASSWORD = +MYSQL_DATABASE = + +# pgsql +PG_HOST = 127.0.0.1 +PG_PORT = 5432 +PG_USERNAME = +PG_PASSWORD = +PG_DATABASE = +PG_SCHEMA = default + +# sqlite +SQLITE_DATABASE = "base_path() . '/database.sqlite'" +SQLITE_PREFIX = + +# log +LOG_MAX_FIlES = 30 +LOG_MAX_FILES_DEBUG = 3 +LOG_MAX_FIlES_ERROR = 90 \ No newline at end of file diff --git a/README.md b/README.md index 9538cd9..639d199 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,27 @@ -
-

webman

+# 基于docker的webman-jsonrpc -基于workerman开发的超高性能PHP框架 +我们在`php:8.1-cli`基础上安装了运行webman必要的一些扩展和开发中常用的扩展,以及composer,制作成`workerman:8.1`镜像,因此在开发环境中不需要再额外配置php环境,直接写业务代码即可。 +## 依赖 -

学习

+只要系统环境中有docker即可,不需要安装php环境 - +## 使用方法 -
- -

赞助商

- -

特别赞助

- - - - -

铂金赞助

- - - -

金牌赞助

- - -
- - -
-

LICENSE

-The webman is open-sourced software licensed under the MIT. -
- -
+```sh +# 启动 +./start +# composer +./composer install +./conposer require xxxx +``` +## 一些有用的文件 +| 文件 | 作用 | 用法或说明 | +|---|---|---| +|composer|调起容器中的`composer`命令的shell脚本|`./composer $args...`| +|start|调起容器中的`php start.php`命令的shell脚本|`./start`或`./start -d`| +|docker-compose.yml|运行容器的编排文件|一般不需要理会这个文件,composer和start脚本都需要依赖这个文件| +|docker.conf|定义运行服务的容器名称和使用的镜像版本|注意container_name不要与系统中其他服务的容器重名| +|php.ini|映射到容器中的php.ini配置文件|容器中已经安装的扩展都有单独的配置文件,这里不会有体现| diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 435a182..7da06ec 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -2,17 +2,22 @@ namespace app\controller; +use ErrorException; +use Exception; +use support\Log; use support\Request; +use Wandoubaba\Res; class IndexController { public function index(Request $request) { - static $readme; - if (!$readme) { - $readme = file_get_contents(base_path('README.md')); - } - return $readme; + // var_dump(eval("return " . env('MAX_PACKAGE_SIZE', 10 * 1024 * 1024) . ";")); + // throw new Exception(config('redis.default.password') ?: 'null', 999); + $res = new Res(); + $res->setData([env('LOG_MAX_FILES_DEBUG') ?: env('LOG_MAX_FIlES') ?: 7]); + Log::channel('error')->error('错了'); + return json($res); } public function view(Request $request) diff --git a/app/exception/Handler.php b/app/exception/Handler.php new file mode 100644 index 0000000..d5d4ca3 --- /dev/null +++ b/app/exception/Handler.php @@ -0,0 +1,51 @@ + app\exception\Handler::class, + */ +class Handler extends \support\exception\Handler +{ + /** + * 自定义异常响应 + * + * @author Aaron + * + * @param \Webman\Http\Request $request + * @param \Throwable $exception + * + * @return \Webman\Http\Response + */ + public function render(Request $request, Throwable $exception): Response + { + $res = new Res(); + $resData = null; + if (config('app.debug') == 'true') { + $resData = [ + 'request_path' => $request->path(), + 'post_data' => $request->post(), + 'query_param' => $request->get(), + 'headers' => $request->header(), + ]; + $resData['exception'] = [ + 'code' => $exception->getCode(), + 'file' => $exception->getFile(), + 'line' => $exception->getLine(), + 'message' => $exception->getMessage(), + 'trace' => $exception->getTrace(), + ]; + } + $res->setCode($exception->getCode()) + ->setMsg($exception->getMessage()) + ->setData($resData); + return json($res); + } +} diff --git a/app/global.php b/app/global.php new file mode 100644 index 0000000..d6eae46 --- /dev/null +++ b/app/global.php @@ -0,0 +1,4 @@ +=7.4.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, "autoload": { "psr-4": { "Psr\\Container\\": "src/" @@ -1290,22 +1179,22 @@ ], "support": { "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/2.0.2" + "source": "https://github.com/php-fig/container/tree/1.1.2" }, - "time": "2021-11-05T16:47:00+00:00" + "time": "2021-11-05T16:50:12+00:00" }, { "name": "psr/log", - "version": "3.0.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" + "reference": "ef29f6d262798707a9edd554e2b82517ef3a9376" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", - "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", + "url": "https://api.github.com/repos/php-fig/log/zipball/ef29f6d262798707a9edd554e2b82517ef3a9376", + "reference": "ef29f6d262798707a9edd554e2b82517ef3a9376", "shasum": "" }, "require": { @@ -1314,7 +1203,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1340,31 +1229,31 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/3.0.0" + "source": "https://github.com/php-fig/log/tree/2.0.0" }, - "time": "2021-07-14T16:46:02+00:00" + "time": "2021-07-14T16:41:46+00:00" }, { "name": "psr/simple-cache", - "version": "3.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/simple-cache.git", - "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865" + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865", - "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", "shasum": "" }, "require": { - "php": ">=8.0.0" + "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { @@ -1379,7 +1268,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" + "homepage": "http://www.php-fig.org/" } ], "description": "Common interfaces for simple caching", @@ -1391,9 +1280,108 @@ "simple-cache" ], "support": { - "source": "https://github.com/php-fig/simple-cache/tree/3.0.0" + "source": "https://github.com/php-fig/simple-cache/tree/master" }, - "time": "2021-10-29T13:26:27+00:00" + "time": "2017-10-23T01:57:42+00:00" + }, + { + "name": "symfony/console", + "version": "v5.4.28", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "f4f71842f24c2023b91237c72a365306f3c58827" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/f4f71842f24c2023b91237c72a365306f3c58827", + "reference": "f4f71842f24c2023b91237c72a365306f3c58827", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php73": "^1.9", + "symfony/polyfill-php80": "^1.16", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/string": "^5.1|^6.0" + }, + "conflict": { + "psr/log": ">=3", + "symfony/dependency-injection": "<4.4", + "symfony/dotenv": "<5.1", + "symfony/event-dispatcher": "<4.4", + "symfony/lock": "<4.4", + "symfony/process": "<4.4" + }, + "provide": { + "psr/log-implementation": "1.0|2.0" + }, + "require-dev": { + "psr/log": "^1|^2", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/event-dispatcher": "^4.4|^5.0|^6.0", + "symfony/lock": "^4.4|^5.0|^6.0", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/var-dumper": "^4.4|^5.0|^6.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Eases the creation of beautiful and testable command line interfaces", + "homepage": "https://symfony.com", + "keywords": [ + "cli", + "command-line", + "console", + "terminal" + ], + "support": { + "source": "https://github.com/symfony/console/tree/v5.4.28" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-08-07T06:12:30+00:00" }, { "name": "symfony/deprecation-contracts", @@ -1544,6 +1532,171 @@ ], "time": "2023-01-26T09:26:14+00:00" }, + { + "name": "symfony/polyfill-intl-grapheme", + "version": "v1.28.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-grapheme.git", + "reference": "875e90aeea2777b6f135677f618529449334a612" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/875e90aeea2777b6f135677f618529449334a612", + "reference": "875e90aeea2777b6f135677f618529449334a612", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.28-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Grapheme\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's grapheme_* functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "grapheme", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.28.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-01-26T09:26:14+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.28.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", + "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.28-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.28.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-01-26T09:26:14+00:00" + }, { "name": "symfony/polyfill-mbstring", "version": "v1.28.0", @@ -1627,6 +1780,85 @@ ], "time": "2023-07-28T09:04:16+00:00" }, + { + "name": "symfony/polyfill-php73", + "version": "v1.28.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fe2f306d1d9d346a7fee353d0d5012e401e984b5", + "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.28-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php73/tree/v1.28.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-01-26T09:26:14+00:00" + }, { "name": "symfony/polyfill-php80", "version": "v1.28.0", @@ -1710,6 +1942,175 @@ ], "time": "2023-01-26T09:26:14+00:00" }, + { + "name": "symfony/service-contracts", + "version": "v2.5.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/service-contracts.git", + "reference": "4b426aac47d6427cc1a1d0f7e2ac724627f5966c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/4b426aac47d6427cc1a1d0f7e2ac724627f5966c", + "reference": "4b426aac47d6427cc1a1d0f7e2ac724627f5966c", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "psr/container": "^1.1", + "symfony/deprecation-contracts": "^2.1|^3" + }, + "conflict": { + "ext-psr": "<1.1|>=2" + }, + "suggest": { + "symfony/service-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Service\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to writing services", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/service-contracts/tree/v2.5.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-05-30T19:17:29+00:00" + }, + { + "name": "symfony/string", + "version": "v6.3.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/string.git", + "reference": "13d76d0fb049051ed12a04bef4f9de8715bea339" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/string/zipball/13d76d0fb049051ed12a04bef4f9de8715bea339", + "reference": "13d76d0fb049051ed12a04bef4f9de8715bea339", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-intl-grapheme": "~1.0", + "symfony/polyfill-intl-normalizer": "~1.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/translation-contracts": "<2.5" + }, + "require-dev": { + "symfony/error-handler": "^5.4|^6.0", + "symfony/http-client": "^5.4|^6.0", + "symfony/intl": "^6.2", + "symfony/translation-contracts": "^2.5|^3.0", + "symfony/var-exporter": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "files": [ + "Resources/functions.php" + ], + "psr-4": { + "Symfony\\Component\\String\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way", + "homepage": "https://symfony.com", + "keywords": [ + "grapheme", + "i18n", + "string", + "unicode", + "utf-8", + "utf8" + ], + "support": { + "source": "https://github.com/symfony/string/tree/v6.3.5" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-09-18T10:38:32+00:00" + }, { "name": "symfony/translation", "version": "v6.3.3", @@ -1885,34 +2286,39 @@ }, { "name": "symfony/var-dumper", - "version": "v6.3.5", + "version": "v5.4.29", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "3d9999376be5fea8de47752837a3e1d1c5f69ef5" + "reference": "6172e4ae3534d25ee9e07eb487c20be7760fcc65" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/3d9999376be5fea8de47752837a3e1d1c5f69ef5", - "reference": "3d9999376be5fea8de47752837a3e1d1c5f69ef5", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/6172e4ae3534d25ee9e07eb487c20be7760fcc65", + "reference": "6172e4ae3534d25ee9e07eb487c20be7760fcc65", "shasum": "" }, "require": { - "php": ">=8.1", - "symfony/deprecation-contracts": "^2.5|^3", - "symfony/polyfill-mbstring": "~1.0" + "php": ">=7.2.5", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php80": "^1.16" }, "conflict": { - "symfony/console": "<5.4" + "symfony/console": "<4.4" }, "require-dev": { "ext-iconv": "*", - "symfony/console": "^5.4|^6.0", - "symfony/http-kernel": "^5.4|^6.0", - "symfony/process": "^5.4|^6.0", - "symfony/uid": "^5.4|^6.0", + "symfony/console": "^4.4|^5.0|^6.0", + "symfony/http-kernel": "^4.4|^5.0|^6.0", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/uid": "^5.1|^6.0", "twig/twig": "^2.13|^3.0.4" }, + "suggest": { + "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", + "ext-intl": "To show region name in time zone dump", + "symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script" + }, "bin": [ "Resources/bin/var-dump-server" ], @@ -1949,7 +2355,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v6.3.5" + "source": "https://github.com/symfony/var-dumper/tree/v5.4.29" }, "funding": [ { @@ -1965,7 +2371,7 @@ "type": "tidelift" } ], - "time": "2023-09-12T10:11:35+00:00" + "time": "2023-09-12T10:09:58+00:00" }, { "name": "vlucas/phpdotenv", @@ -2053,16 +2459,16 @@ }, { "name": "voku/portable-ascii", - "version": "2.0.1", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/voku/portable-ascii.git", - "reference": "b56450eed252f6801410d810c8e1727224ae0743" + "reference": "87337c91b9dfacee02452244ee14ab3c43bc485a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/voku/portable-ascii/zipball/b56450eed252f6801410d810c8e1727224ae0743", - "reference": "b56450eed252f6801410d810c8e1727224ae0743", + "url": "https://api.github.com/repos/voku/portable-ascii/zipball/87337c91b9dfacee02452244ee14ab3c43bc485a", + "reference": "87337c91b9dfacee02452244ee14ab3c43bc485a", "shasum": "" }, "require": { @@ -2099,7 +2505,7 @@ ], "support": { "issues": "https://github.com/voku/portable-ascii/issues", - "source": "https://github.com/voku/portable-ascii/tree/2.0.1" + "source": "https://github.com/voku/portable-ascii/tree/1.6.1" }, "funding": [ { @@ -2123,7 +2529,103 @@ "type": "tidelift" } ], - "time": "2022-03-08T17:03:00+00:00" + "time": "2022-01-24T18:55:24+00:00" + }, + { + "name": "wandoubaba/res", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/wandoubaba/res.git", + "reference": "679dfee8fa357bc98fe6c585e12a01994aee0046" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wandoubaba/res/zipball/679dfee8fa357bc98fe6c585e12a01994aee0046", + "reference": "679dfee8fa357bc98fe6c585e12a01994aee0046", + "shasum": "" + }, + "require": { + "php": ">=7.4" + }, + "require-dev": { + "phpunit/phpunit": "^10.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Wandoubaba\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "wandoubaba", + "email": "wandoubaba517@gmail.com" + } + ], + "description": "一个简单的Res模型,包含code、msg、data属性,可用于HTTP接口的返回值", + "support": { + "issues": "https://github.com/wandoubaba/res/issues", + "source": "https://github.com/wandoubaba/res/tree/v1.0.4" + }, + "time": "2023-10-18T08:08:05+00:00" + }, + { + "name": "webman/console", + "version": "v1.2.39", + "source": { + "type": "git", + "url": "https://github.com/webman-php/console.git", + "reference": "d0ed633fa4ea7c6e7d2f5961a0cc1f5f890a5079" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webman-php/console/zipball/d0ed633fa4ea7c6e7d2f5961a0cc1f5f890a5079", + "reference": "d0ed633fa4ea7c6e7d2f5961a0cc1f5f890a5079", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^2.0", + "symfony/console": ">=5.0" + }, + "require-dev": { + "workerman/webman": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Webman\\Console\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "walkor", + "email": "walkor@workerman.net", + "homepage": "http://www.workerman.net", + "role": "Developer" + } + ], + "description": "Webman console", + "homepage": "http://www.workerman.net", + "keywords": [ + "webman console" + ], + "support": { + "email": "walkor@workerman.net", + "forum": "http://www.workerman.net/questions", + "issues": "https://github.com/webman-php/console/issues", + "source": "https://github.com/webman-php/console", + "wiki": "http://www.workerman.net/doc/webman" + }, + "time": "2023-10-13T07:42:14+00:00" }, { "name": "workerman/webman-framework", diff --git a/config/app.php b/config/app.php index f26e358..53cbce2 100644 --- a/config/app.php +++ b/config/app.php @@ -15,7 +15,7 @@ use support\Request; return [ - 'debug' => true, + 'debug' => env('DEBUG', false), 'error_reporting' => E_ALL, 'default_timezone' => 'Asia/Shanghai', 'request_class' => Request::class, diff --git a/config/autoload.php b/config/autoload.php index 69a8135..1c6df91 100644 --- a/config/autoload.php +++ b/config/autoload.php @@ -14,6 +14,7 @@ return [ 'files' => [ + base_path() . '/app/global.php', base_path() . '/app/functions.php', base_path() . '/support/Request.php', base_path() . '/support/Response.php', diff --git a/config/database.php b/config/database.php index 7dc463a..29d4806 100644 --- a/config/database.php +++ b/config/database.php @@ -12,4 +12,39 @@ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ -return []; +return [ + 'default' => env('DB_DEFAULT_DRIVER', 'mysql'), + 'connections' => [ + 'mysql' => [ + 'driver' => 'mysql', + 'host' => env('MYSQL_HOST', '127.0.0.1'), + 'port' => env('MYSQL_PORT', 3306), + 'database' => env('MYSQL_DATABASE', 'webman'), + 'username' => env('MYSQL_USERNAME', 'webman'), + 'password' => env('MYSQL_PASSWORD', ''), + 'unix_socket' => '', + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + 'strict' => true, + 'engine' => null, + ], + 'sqlite' => [ + 'driver' => 'sqlite', + 'database' => eval("return " . env('SQLITE_DATABASE', '') . ";"), + 'prefix' => env('SQLITE_PREFIX', ''), + ], + 'pgsql' => [ + 'driver' => 'pgsql', + 'host' => env('PG_HOST', '127.0.0.1'), + 'port' => env('PG_PORT', 5432), + 'database' => env('PG_DATABASE', 'webman'), + 'username' => env('PG_USERNAME', 'webman'), + 'password' => env('PG_PASSWORD', ''), + 'charset' => 'utf8', + 'prefix' => '', + 'schema' => env('PG_SCHEMA', 'public'), + 'sslmode' => 'prefer', + ], + ] +]; diff --git a/config/exception.php b/config/exception.php index f2aede3..bdbc2e3 100644 --- a/config/exception.php +++ b/config/exception.php @@ -13,5 +13,6 @@ */ return [ - '' => support\exception\Handler::class, + // '' => support\exception\Handler::class, + '' => app\exception\Handler::class, ]; \ No newline at end of file diff --git a/config/log.php b/config/log.php index 7f05de5..c4b2815 100644 --- a/config/log.php +++ b/config/log.php @@ -29,4 +29,59 @@ return [ ] ], ], + 'debug' => [ + 'handlers' => [ + [ + 'class' => Monolog\Handler\RotatingFileHandler::class, + 'constructor' => [ + runtime_path() . '/logs/debug/debug.log', + env('LOG_MAX_FILES_DEBUG') ?: env('LOG_MAX_FIlES') ?: 7, //$maxFiles + Monolog\Logger::DEBUG, + ], + 'formatter' => [ + 'class' => Monolog\Formatter\LineFormatter::class, + 'constructor' => [null, 'Y-m-d H:i:s.u', true, true], + ], + ], [ + // 把日志输出到控制台 + 'class' => Monolog\Handler\StreamHandler::class, + 'constructor' => [ + 'php://stdout', + Monolog\Logger::DEBUG, + ], + 'formatter' => [ + 'class' => Monolog\Formatter\LineFormatter::class, + 'constructor' => [null, 'Y-m-d H:i:s.u', true, true], + ], + ], + ], + ], + 'error' => [ + 'handlers' => [ + [ + 'class' => Monolog\Handler\RotatingFileHandler::class, + 'constructor' => [ + runtime_path() . '/logs/error/error.log', + env('LOG_MAX_FILES_ERROR') ?: env('LOG_MAX_FIlES') ?: 7, //$maxFiles + Monolog\Logger::DEBUG, + ], + 'formatter' => [ + 'class' => Monolog\Formatter\LineFormatter::class, + 'constructor' => [null, 'Y-m-d H:i:s.u', true, true], + ], + ], [ + // 把日志输出到控制台 + 'class' => Monolog\Handler\StreamHandler::class, + 'constructor' => [ + 'php://stdout', + Monolog\Logger::DEBUG, + ], + 'formatter' => [ + 'class' => Monolog\Formatter\LineFormatter::class, + 'constructor' => [null, 'Y-m-d H:i:s.u', true, true], + ], + ], + ], + ], + ]; diff --git a/config/plugin/webman/console/app.php b/config/plugin/webman/console/app.php new file mode 100644 index 0000000..074e986 --- /dev/null +++ b/config/plugin/webman/console/app.php @@ -0,0 +1,24 @@ + true, + + 'build_dir' => BASE_PATH . DIRECTORY_SEPARATOR . 'build', + + 'phar_filename' => 'webman.phar', + + 'bin_filename' => 'webman.bin', + + 'signature_algorithm'=> Phar::SHA256, //set the signature algorithm for a phar and apply it. The signature algorithm must be one of Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, or Phar::OPENSSL. + + 'private_key_file' => '', // The file path for certificate or OpenSSL private key file. + + 'exclude_pattern' => '#^(?!.*(composer.json|/.github/|/.idea/|/.git/|/.setting/|/runtime/|/vendor-bin/|/build/|/vendor/webman/admin/))(.*)$#', + + 'exclude_files' => [ + '.env', 'LICENSE', 'composer.json', 'composer.lock', 'start.php', 'webman.phar', 'webman.bin' + ], + + 'custom_ini' => ' +memory_limit = 256M + ', +]; diff --git a/config/redis.php b/config/redis.php index 2f9757a..dc3eabc 100644 --- a/config/redis.php +++ b/config/redis.php @@ -14,9 +14,9 @@ return [ 'default' => [ - 'host' => '127.0.0.1', - 'password' => null, - 'port' => 6379, - 'database' => 0, + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => env('REDIS_DATABASE', 0), ], ]; diff --git a/config/server.php b/config/server.php index adccf2a..ab3f1de 100644 --- a/config/server.php +++ b/config/server.php @@ -13,11 +13,11 @@ */ return [ - 'listen' => '', + 'listen' => env('SERVER_LISTEN', 'http://0.0.0.0:8787'), 'transport' => 'tcp', 'context' => [], - 'name' => 'webman', - 'count' => 1, + 'name' => env('SERVER_NAME', 'webman'), + 'count' => eval("return " . env('SERVER_COUNT', cpu_count() * 4) . ";"), 'user' => '', 'group' => '', 'reusePort' => false, @@ -27,5 +27,5 @@ return [ 'status_file' => runtime_path() . '/webman.status', 'stdout_file' => runtime_path() . '/logs/stdout.log', 'log_file' => runtime_path() . '/logs/workerman.log', - 'max_package_size' => 10 * 1024 * 1024 + 'max_package_size' => eval("return " . env('MAX_PACKAGE_SIZE', 10 * 1024 * 1024) . ";"), ]; diff --git a/docker-compose-dev.yml b/docker-compose.yml similarity index 92% rename from docker-compose-dev.yml rename to docker-compose.yml index 1f9b176..f5a35c3 100644 --- a/docker-compose-dev.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.1" services: webman-jsonrpc: - image: registry.cn-shanghai.aliyuncs.com/wandoubaba/workerman:8.1 + image: registry.cn-shanghai.aliyuncs.com/wandoubaba/workerman:${WORKERMAN_IMAGE_VERSION} container_name: webman-jsonrpc network_mode: host restart: always diff --git a/docker.conf b/docker.conf new file mode 100644 index 0000000..6106e90 --- /dev/null +++ b/docker.conf @@ -0,0 +1,2 @@ +container_name=webman-jsonrpc +image_version=8.1 \ No newline at end of file diff --git a/start b/start index 12c2666..a3f9183 100755 --- a/start +++ b/start @@ -1,9 +1,22 @@ #!/bin/bash -service_name="webman-jsonrpc" -compose_file="docker-compose-dev.yml" -if docker inspect -f '{{.State.Running}}' $service_name >/dev/null 2>&1; then - docker rm -f $service_name +# 读取docker.conf文件 +source docker.conf + +# 设置系统环境变量 +export WORKERMAN_CONTAINER_NAME=$container_name +export WORKERMAN_IMAGE_VERSION=$image_version + +# 判断WORKERMAN_CONTAINER_NAME的docker容器是否存在,如果存在,删除它 +if docker ps -a --format '{{.Names}}' | grep -q "^$WORKERMAN_CONTAINER_NAME$"; then + docker rm -f $WORKERMAN_CONTAINER_NAME fi -docker compose -f $compose_file up +docker compose run --rm $WORKERMAN_CONTAINER_NAME composer install + +# 根据参数执行docker compose up命令 +if [[ $1 == "-d" ]]; then + docker compose up -d +else + docker compose up +fi diff --git a/webman b/webman new file mode 100755 index 0000000..00520d1 --- /dev/null +++ b/webman @@ -0,0 +1,45 @@ +#!/usr/bin/env php +setName('webman cli'); +$cli->installInternalCommands(); +if (is_dir($command_path = Util::guessPath(app_path(), '/command', true))) { + $cli->installCommands($command_path); +} + +foreach (config('plugin', []) as $firm => $projects) { + if (isset($projects['app'])) { + if ($command_str = Util::guessPath(base_path() . "/plugin/$firm", 'command')) { + $command_path = base_path() . "/plugin/$firm/$command_str"; + $cli->installCommands($command_path, "plugin\\$firm\\$command_str"); + } + } + foreach ($projects as $name => $project) { + if (!is_array($project)) { + continue; + } + foreach ($project['command'] ?? [] as $command) { + $cli->add(Container::get($command)); + } + } +} + +$cli->run();