Commit d610bef67d18948e5f4c6eadd8aae7062e57e189
1 parent
a209ad36
chore: add diagnostics for .env loading failure
Showing
1 changed file
with
17 additions
and
3 deletions
| @@ -11,10 +11,24 @@ require_once __DIR__ . '/auth.php'; | @@ -11,10 +11,24 @@ require_once __DIR__ . '/auth.php'; | ||
| 11 | require_once __DIR__ . '/device.php'; | 11 | require_once __DIR__ . '/device.php'; |
| 12 | 12 | ||
| 13 | // Load .env | 13 | // Load .env |
| 14 | -if (class_exists('Dotenv\Dotenv') && file_exists(__DIR__ . '/.env')) { | ||
| 15 | - $dotenv = Dotenv\Dotenv::createImmutable(__DIR__); | ||
| 16 | - $dotenv->load(); | 14 | +$envFile = __DIR__ . '/.env'; |
| 15 | +$hasDotenv = class_exists('Dotenv\Dotenv'); | ||
| 16 | +$hasEnvFile = file_exists($envFile); | ||
| 17 | + | ||
| 18 | +$logMsg = ""; | ||
| 19 | +if ($hasDotenv && $hasEnvFile) { | ||
| 20 | + try { | ||
| 21 | + $dotenv = Dotenv\Dotenv::createImmutable(__DIR__); | ||
| 22 | + $dotenv->load(); | ||
| 23 | + $logMsg = "[" . date('Y-m-d H:i:s') . "] Startup - .env loaded successfully.\n"; | ||
| 24 | + } catch (Exception $e) { | ||
| 25 | + $logMsg = "[" . date('Y-m-d H:i:s') . "] Startup - Error loading .env: " . $e->getMessage() . "\n"; | ||
| 26 | + } | ||
| 27 | +} else { | ||
| 28 | + $logMsg = "[" . date('Y-m-d H:i:s') . "] Startup - Skipping .env load. Dotenv installed: " . ($hasDotenv ? 'YES' : 'NO') . ", .env exists: " . ($hasEnvFile ? 'YES' : 'NO') . "\n"; | ||
| 17 | } | 29 | } |
| 30 | +file_put_contents(__DIR__ . '/debug.log', $logMsg, FILE_APPEND); | ||
| 31 | +echo $logMsg; | ||
| 18 | 32 | ||
| 19 | // 加载配置文件 | 33 | // 加载配置文件 |
| 20 | $config = require __DIR__ . '/config.php'; | 34 | $config = require __DIR__ . '/config.php'; |
Please
register
or
login
to post a comment