PHP code example of myphps / my
1. Go to this page and download the library: Download myphps/my library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
myphps / my example snippets
$cfg = [
'db' => [...], // 数据库连接(支持 mysql/sqlite/pgsql/mssql/oracle)
'redis' => [...], // Redis 连接
'log_dir' => '...', // 日志目录
'log_level' => 0, // 日志级别 0-5
'encode_key' => '...', // 数据编码密钥
'jwt_key' => '...', // JWT 密钥
'middleware' => [...], // 中间件配置
'url_maps' => [...], // URL 映射
'module_maps' => [...], // 模块映射
];
return [
'name' => 'myApp', // 服务名
'ip' => '0.0.0.0', // 监听地址
'port' => 6051, // 监听端口
'type' => 'http', // 类型:http/websocket/tcp/udp
'setting' => [
'count' => 8, // 进程数(建议 CPU 核数 × 1~4)
'static_path' => '', // 静态文件目录(Workerman)
],
];
bash
# 生成所有表的 Model
php cli.php Model 1 "common\model" "\common\CommonModel"
# 生成指定表的 Model
php cli.php Model 表名 "common\model" "\common\CommonModel"
# 生成多张表(逗号分隔)
php cli.php Model "table1,table2" "common\model" "\common\CommonModel"
bash
# 默认 Workerman 运行
php app.php
# 指定参数运行
php app.php -p 6051 -c 8
# Swoole 模式运行
php app.php -s
# 调试模式运行
php app.php --console
# 重启 / 平滑重载 / 停止
php app.php restart
php app.php reload
php app.php stop
bash
# 生成 phar 文件到 dist/ 目录
php cli.php phar
# 如提示 phar.readonly 限制,使用:
php -d phar.readonly=0 cli.php phar
# 运行 phar
php my.phar
bash
# 安装工具
composer sofphp/php-cs-fixer
# 代码格式化
php-cs-fixer fix --config=./.php-cs-fixer.dist.php
# 静态分析
phpstan analyse -c ./phpstan.neon.dist --memory-limit 1G