Short Story: I'm looking for a work around to PHP $_SERVER[] variables not being available (only) in a case where a PHP script file is being run from a Windows Task Scheduler scheduled event.
I have two Windows 2008 R2 Servers with PHP version 7.1 running on both servers. I've been calling server #1 'Production' and server #2 'Development'. Each server has it's own MySQL db.
On the pages I've been writing, for MySQL db read/writes, I've been using $_SERVER['SERVER_NAME'], to identify what server is running the script (if the page is running on the development server, use the IP address of the MySQL db on the development server. If the current server is the production server, use the production database IP).
That works perfectly fine for me. The exception is when I use the Windows Task Scheduler to schedule an automated task. In this case, I'm creating a single stand alone PHP script file to send an email with some information from that database.
PHP script file to send an email with some information from the db results in:
- Running the page in a browser results in $_SERVER['SERVER_NAME'] being defined (works good).
- If Windows Task scheduler runs the PHP page this results in $_SERVER['SERVER_NAME'] not being defined
Would anyone know how I could make the $_SERVER[] variables available to a .php file being run by a Windows Scheduled Taks (where the task scheduler is of course pointing towards the PHP.exe with a referee to this script .php file)? Or, is there another way besides the $_SERVER[] variable to detect the name of the server the script is being run on?
apiservlets designed for each task. - YvesLeBorg