Reloading .env variables without restarting server (Laravel 5, shared hosting)

前端 未结 7 2211
旧巷少年郎
旧巷少年郎 2020-12-23 13:46

My Laravel 5 has run OK until the database was configured, then found this error:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name o         


        
7条回答
  •  情书的邮戳
    2020-12-23 14:28

    In case anybody stumbles upon this question who cannot reload their webserver (long running console command like a queue runner) or needs to reload their .env file mid-request, i found a way to properly reload .env variables in laravel 5.

    use Dotenv;
    use InvalidArgumentException;
    
    try {
        Dotenv::makeMutable();
        Dotenv::load(app()->environmentPath(), app()->environmentFile());
        Dotenv::makeImmutable();
    } catch (InvalidArgumentException $e) {
        //
    }
    

提交回复
热议问题