I have a development platform with a development server and a production server. I’ll upload my projects to both servers, but I want exceptions to be handled differently on development servers. Because I want to be able to upload the exact same code to both servers, I want php to detect which server it is running on and act accordingly. I thought this would be an easy task but it isn’t.
So far I tried the following:
Setting an environment variable in /etc/profile and reading it using php’s getenv function.
Didn’t work because from php you can only read a couple of environment variables, and not those in etc/profile.
Getting the server address and/or host using the $_SERVER superglobal.
Didn’t work for crons.
Setting a custom non-standard setting (error_message_mode) in php.ini.
Didn’t work because only standard settings will be available in ini_get.
Getting the ip address of the server using some linux function.
I frankly don’t know how to do this. Any ideas?
By the way, I am now using display_startup_errors and ini_get in order to get the mode (default or live), because it is recommended to only turn on this flag in debug mode. However, I still like to know how to set custom server-specific flags in php.
I thought of that approach. But I want to be able to upload identical code to both servers, and have the code itself figure out whether it is on a development server or live server. The define-approach is great normally, but it requires you to edit the project code every time you upload the file to a test or live server.