swoole php配置文件,easyswoole自义命令加载自定义配置文件

需求: 目前框架默认只会加载两个配置文件 dev.php 和 produce.php 只有本地开发和线上生产两个环境, 但是现在需要一个线上测试环境的配置.

版本: easyswoole-3.3.7

loadEnv 加载配置文件的方法

启动命令会执行loadEnv方法, 我们自己复制Command/DefaultCommand/Start.php 文件加载自己的配置文件覆盖之前的配置

在自己的项目中 App/Command/test.php 增加一个文件 如何自定义命令点我

/**

* Created by PhpStorm.

* User: yf

* Date: 2019-01-24

* Time: 23:44

*/

namespace EasySwoole\EasySwoole\Command\DefaultCommand;

use EasySwoole\EasySwoole\Command\CommandInterface;

use EasySwoole\EasySwoole\Command\Utility;

use EasySwoole\EasySwoole\Config;

use EasySwoole\EasySwoole\Core;

use EasySwoole\EasySwoole\ServerManager;

use EasySwoole\EasySwoole\SysConst;

class Start implements CommandInterface

{

public function commandName(): string

{

// TODO: Implement commandName() method.

return 'start';

}

public function exec(array $args): ?string

{

// TODO: Implement exec() method.

Utility::opCacheClear();

$response = Utility::easySwooleLog();

$mode = 'develop';

if (!Core::getInstance()->isDev()) {

$mode = 'produce';

}

$conf = Config::getInstance();

if (in_array("d", $args) || in_array("daemonize", $args)) {

$conf->setConf("MAIN_SERVER.SETTING.daemonize", true);

}

//create main Server

Core::getInstance()->globalInitialize()->createServer();

//重点这一行

Config::getInstance()->loadEnv( EASYSWOOLE_ROOT.'/test.php');

$serverType = $conf->getConf('MAIN_SERVER.SERVER_TYPE');

switch ($serverType) {

case EASYSWOOLE_SERVER:

{

$serverType = 'SWOOLE_SERVER';

break;

}

case EASYSWOOLE_WEB_SERVER:

{

$serverType = 'SWOOLE_WEB';

break;

}

case EASYSWOOLE_WEB_SOCKET_SERVER:

{

$serverType = 'SWOOLE_WEB_SOCKET';

break;

}

case EASYSWOOLE_REDIS_SERVER:

{

$serverType = 'SWOOLE_REDIS';

break;

}

default:

{

$serverType = 'UNKNOWN';

}

}

$response = $response . Utility::displayItem('main server', $serverType) . "\n";

$response = $response . Utility::displayItem('listen address', $conf->getConf('MAIN_SERVER.LISTEN_ADDRESS')) . "\n";

$response = $response . Utility::displayItem('listen port', $conf->getConf('MAIN_SERVER.PORT')) . "\n";

$list = ServerManager::getInstance()->getSubServerRegister();

$index = 1;

foreach ($list as $serverName => $item) {

if (empty($item['setting'])) {

$type = $serverType;

} else {

$type = $item['type'] % 2 > 0 ? 'SWOOLE_TCP' : 'SWOOLE_UDP';

}

$response = $response . Utility::displayItem("sub server:{$serverName}", "{$type}@{$item['listenAddress']}:{$item['port']}") . "\n";

$index++;

}

$ips = swoole_get_local_ip();

foreach ($ips as $eth => $val) {

$response = $response . Utility::displayItem('ip@' . $eth, $val) . "\n";

}

$data = $conf->getConf('MAIN_SERVER.SETTING');

if(empty($data['user'])){

$data['user'] = get_current_user();

}

if(!isset($data['daemonize'])){

$data['daemonize'] = false;

}

foreach ($data as $key => $datum){

$response = $response . Utility::displayItem($key,$datum) . "\n";

}

$response = $response . Utility::displayItem('swoole version', phpversion('swoole')) . "\n";

$response = $response . Utility::displayItem('php version', phpversion()) . "\n";

$response = $response . Utility::displayItem('easy swoole', SysConst::EASYSWOOLE_VERSION) . "\n";

$response = $response . Utility::displayItem('develop/produce', $mode) . "\n";

$response = $response . Utility::displayItem('temp dir', EASYSWOOLE_TEMP_DIR) . "\n";

$response = $response . Utility::displayItem('log dir', EASYSWOOLE_LOG_DIR) . "\n";

echo $response;

Core::getInstance()->start();

return null;

}

public function help(array $args): ?string

{

// TODO: Implement help() method.

$logo = Utility::easySwooleLog();

return $logo . <<

\e[33mOperation:\e[0m

\e[31m php easyswoole start [arg1] [arg2]\e[0m

\e[33mIntro:\e[0m

\e[36m to start current easyswoole server \e[0m

\e[33mArg:\e[0m

\e[32m daemonize \e[0m run in daemonize

\e[32m produce \e[0m load produce.php

HELP_START;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Winddows 上的 PHP Swoole Loader 扩展文件是指用于在 Windows 系统上和运行 Swoole PHP 框架的扩展文件Swoole 是一个基于 PHP 的高性能网络通信引擎和异步并发框架,它提供了强大的异步、协程、多进程等功能,可以帮助我们更好地开发高性能的网络应用。 在 Windows 系统上使用 Swoole 需要安装相应的 Swoole Loader 扩展文件。首先,需要确保已经安装了 PHP 环境,然后可以通过以下步骤来安装 Swoole Loader 扩展文件: 1. 获取 Swoole Loader 扩展文件:可以从官方网站的下页面(https://www.swoole.co.uk/download)下适合 Windows 系统的 Swoole Loader 扩展文件。 2. 将扩展文件放置在 PHP 的扩展目录中:找到 PHP 安装目录下的 "ext" 文件夹,将下Swoole Loader 扩展文件(通常是一个 DLL 文件)复制到该文件夹中。 3. 修改 PHP配置文件:打开 PHP配置文件 php.ini,找到并编辑以下两行: ```ini extension_dir = "ext" extension = swoole_loader.dll ``` 确保 "extension_dir" 配置项指向 PHP 的扩展目录,"extension" 配置项指向 Swoole Loader 扩展文件的名称。 4. 重启 Web 服务器:保存并关闭 php.ini 文件,然后重启使用 PHP 的 Web 服务器(如 Apache、Nginx 等),使修改的配置生效。 安装完成后,可以通过在命令行中执行 "php -m" 命令来查看 Swoole Loader 扩展是否成功。如果成功,即可在 Windows 系统上使用 Swoole 进行开发和运行高性能的 PHP 网络应用。 需要注意的是,由于 Swoole 在设计上更多地关注性能而不是跨平台兼容性,所以在 Windows 系统上使用 Swoole 可能会面临一些问题和限制,建议在 Linux 或 macOS 环境中使用 Swoole 获得更好的性能和稳定性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值