Get server identity when running PHP scripts using CRON

I have a PHP script that I want to run through cron. It should load various configuration data depending on whether the script is running on my local server, QA server or production server. The problem is that when the script is executed via cron, it does not have any identifying information $ _SERVER, which I use to find out in which environment the script is running.

The only thing I could think of was to get cron to attach the parameter to the script, but I was hoping that the best way I should not have to do this. Is there any other way to determine which server the script is on when it is launched from cron?

Thank.

+3
source share
2 answers

I solve the problem as follows: go to script environment variables.

In the case of .htaccess / httpd.conf: SetEnv SITE_NAME x1

In the case of cron (run a script):

#!/bin/bash
export SITE_NAME=x1;
php /path

In both cases, the PHP code to get this environment variable is: getenv('SITE_NAME');

x1 is an example site name.

+3
source

getenv ("COMPUTERNAME") will return the name of the computer on which it is running ...

However, if your script does different things in production for testing, how do you know that this is correct in production?

0
source

Source: https://habr.com/ru/post/1785045/


All Articles