Warning about PHP versions and initialisation files

Discussion about BCA's Internet Hosting Service
User avatar
David Gibson
DG test
Posts: 622
Joined: Thu 16 Mar 2006 23:45

Warning about PHP versions and initialisation files

Post by David Gibson » Sun 11 Jul 2010 12:16

Because I maintain a number of web sites on different servers, I have ended up with three different versions of PHP running, and three different versions of Apache. Its a bit of a pain keeping track of the subtle changes from version to version because, not only are there intrinsic differences (e.g. see http://british-caving.org.uk/phpBB2/viewtopic.php?t=318) but there could be differences in the initialisation files, as set up by the administrator.

For example, I have noticed a setting on the BCA site which could suddenly cause my PHP code to fail if the administrator decides to "tidy up". This is a bit obscure: The BCA site has AUTO_GLOBALS_JIT set to ON (recommended) but this setting is ignored because REGISTER_LONG_ARRAYS and REGISTER_ARGC_ARGV are set to ON (recommended value is OFF). So, if Cookie decides to change these values, my code will fail because it depends on AUTO_GLOBALS_JIT = OFF. Clearly that's my fault for writing untidy code that depends on non-standard settings (well, actually its another case of PHP5 doing things differently to PHP4) but the point is that it is a "trojan horse" in that the problem will not manifest itself until some unspecified point in the future when the administrator "tidies up" the initialisation file. Im noticing a number of these suble initialisation problems. Each one is difficult to find.
The AUTO_GLOBALS_JIT one - when I installed PHP5 on my Localhost - took a whole day to track down.

So ... Im sure you'd do this anyway, Cookie, but could you warn if you are going to change a config file or upgrade to a new version of PHP?

I have a couple of "workarounds" to these problems. Firstly, Im starting to put crucial PHP initialisation settings in my .htaccess file (See php_value and php_flag in http://php.net/manual/en/configuration.changes.php . Secondly, Im also starting to use the ini_set function at the start of my scripts. Both of these actions probably things slow a bit. But it is quite useful because if you have a standard header for each page (as http://bcra.org.uk and http://hidden-earth.org.uk do) which is called via a PHP include command, you can put the ini_set settings in the include file. Since of one these settings governs error reporting you can write a single script that will automatically do a site-wide display of PHP errors if you are on localhost, but hide them if you are on the production site. Thirdly, I have a small HTML page that gathers important system info and displays it. Its like a trimmed-down version of phpinfo(). If anyone would like a copy, please ask.
.