In PHP 7.4, print environment variables into the log file
1. In the container, when the environment variable is obtained for the first time, the configuration value of the production environment is obtained, or it is not obtained (set in the program, when the environment variable is not set, the default setting is the configuration value of the production environment). When the environment variable is obtained for the second time, the configuration value of the test environment is obtained.
2. Decide to print the environment variables to the log file to analyze whether the corresponding environment variables have been obtained. Edit in index.php as follows
file_put_contents(__DIR__.'/../storage/logs/theme-cdn.txt', print_r(date('Y-m-d H:i:s') . '-' . getenv('THEME_ASSET_CDN_BUCKET') . PHP_EOL, true), FILE_APPEND | LOCK_EX);
3. The contents of the final log file are as follows. as shown in Figure 1
/var/www/object/storage/logs # cat theme-cdn.txt
2023-02-23 01:47:06-object-theme-assets-test
2023-02-23 01:47:07-object-theme-assets-test
2023-02-23 01:47:07-object-theme-assets-test
2023-02-23 01:47:07-object-theme-assets-test
2023-02-23 01:47:07-object-theme-assets-test
2023-02-23 01:47:07-object-theme-assets-test
