重复读取.env文件的环境变量

luoyue

问题描述

使用docker构建的php8.3版本运行phar文件时env文件重复读取

程序代码或配置

.env文件

SERVER_APP_NAME=test
SERVER_APP_ADDRESS=0.0.0.0
SERVER_APP_PROT=8792

config/process.php文件

<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

use support\Log;
use support\Request;
use app\process\Http;

global $argv;
$listen = 'http://' . env('SERVER_APP_ADDRESS', '0.0.0.0') . ':' . env('SERVER_APP_PROT', 8080);
print_r($listen."\n");
return [
    env('SERVER_APP_NAME', 'webman') => [
        'handler' => Http::class,
        'listen' => $listen,
        'count' => cpu_count() * 4,
        'user' => '',
        'group' => '',
        'reusePort' => false,
        'eventLoop' => '',
        'context' => [],
        'constructor' => [
            'requestClass' => Request::class,
            'logger' => Log::channel('default'),
            'appPath' => app_path(),
            'publicPath' => public_path()
        ]
    ],
    ...
];

重现问题的步骤

准备好运行环境和代码后执行以下命令

//第一步,打包phar
php webman phar:pack

//第二部,运行docker镜像
docker run -v E:/workerman/webman/build:/opt -w /opt --entrypoint php luoyueapi/webman-mvc -d extension=swoole webman.phar start

运行后可查看结果

操作系统环境及workerman/webman等具体版本

workerman/webman:2.1
webman/console:1.3.15
vlucas/phpdotenv:5.6.1
illuminate/support:12.1.1

252 1 0
1个回答

每个进程会载入一次配置

  • luoyue 4天前

    我的描述应该有问题,抱歉,结果是webman进程和test进程同时存在,打印结果是第一次没有读取到.env,后面就读取到了

  • luoyue 3天前

    隔了一天自动修复了

×
🔝