我看了 http://www.wtbis.cn/q/7564 并根據(jù)walkor大佬的建議,在 support/helper.php 中定義了:
function env($key, $default = null) {
static $env_config = [];
if (!$env_config) {
$env_config = include config_path().'/.env';
}
return $env_config[$key]??$default;
}
來讀取 .env 配置內(nèi)容,其他的配置文件(比如 redis.php、database.php 使用都沒問題,就是在 app.php 中使用:
return [
'debug' => env('debug', false),
。。。
];
時會導(dǎo)致內(nèi)存無限增長,然后服務(wù)退出,請問如何解決呢?謝謝~
發(fā)下報錯,發(fā)全
Active code page: 65001
F:_Projects\ManagementPlatform\Server\webman>php windows.php
VirtualAlloc() failed: [0x00000008] 內(nèi)存資源不足,無法處理此命令。
VirtualFree() failed: [0x000001e7] 試圖訪問無效的地址。
VirtualAlloc() failed: [0x00000008] 內(nèi)存資源不足,無法處理此命令。
VirtualFree() failed: [0x000001e7] 試圖訪問無效的地址。
PHP Fatal error: Out of memory (allocated 1849688064) (tried to allocate 8192 bytes) in F:_Projects\ManagementPlatform\Server\webman\envs.php on line 4
Fatal error: Out of memory (allocated 1849688064) (tried to allocate 8192 bytes) in F:_Projects\ManagementPlatform\Server\webman\envs.php on line 4
謝謝大神~
我測試了一下,如果在app.php中調(diào)用env()方法,會無限載入 app.php 配置文件,我把 include config_path().'/.env'; 改為 include_once 或 require_once后問題解決了,雖然不知為何。。哈哈
謝謝大神, .env 里使用了 runtime_path() 函數(shù),不過 app.php 只是返回一個數(shù)組(包含了 runtime_path 索引),這樣也會循環(huán)調(diào)用么?不太明白。。。