123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /**
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2020/11/5
- * Time: 11:38 AM
- *
- * Service 启动脚本
- * 启动命令 php start.php --service=xxx & (XXX 表示对应的service目录名称) --daemonize=0(是否开启后台运行)
- * @Demo php start.php --service=Article --daemonize=0
- */
- use Mall\Framework\Core\Config;
- use Mall\Framework\Factory;
- // swoole 服务项目目录名称
- define('SWOOLESERVER_NAME', 'swoole_server');
- // 项目根目录
- define('PROJECT_PATH', __DIR__);
- require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Mall' . DIRECTORY_SEPARATOR . 'Bootstrap.php';
- $serviceName = Factory::request()->param('service');
- $serviceName = ucfirst($serviceName);
- $daemonize = intval(Factory::request()->param('daemonize'));
- $serviceConfigPath = __DIR__ . DIRECTORY_SEPARATOR . $serviceName . DIRECTORY_SEPARATOR . 'Config'.DIRECTORY_SEPARATOR.'Config.php';
- if (!file_exists($serviceConfigPath)) {
- exit($serviceConfigPath . 'config file is not found');
- }
- Config::load($serviceConfigPath);
- $service = Config::getInstance()->get('service');
- $buildSwooleConfig = [
- 'worker_num' => 2, // 建议开启核数的1-4倍
- 'daemonize' => $daemonize,
- 'open_length_check' => true, // 开启协议解析
- 'package_length_type' => 'N', // 长度字段的类型
- 'package_length_offset' => 0, //第几个字节是包长度的值
- 'package_body_offset' => PACKAGE_BODY_OFFSET, //第几个字节开始计算包内容
- 'package_max_length' => PACKAGE_MAXLENG, //协议最大长度
- ];
- if($service['ssl'] == true){
- $ssl = Config::getInstance()->get('ssl');
- $buildSwooleConfig = array_merge($buildSwooleConfig, $ssl);
- }
- if ($daemonize) {
- $dir = sys_get_temp_dir();
- $buildSwooleConfig['log_file'] = $dir . DIRECTORY_SEPARATOR . 'swoole_' . $serviceName . '.log';
- echo '控制台信息输出请查看:' . $buildSwooleConfig['log_file'] . "\n";
- }
- Factory::swoole($service, $service['type'])->setConfig($buildSwooleConfig)->begin();
|