Posted on Monday 13 March 2006
I've been testing amfphp with PHP4 and PHP5 lately (PHP5 supports try..catch so the error handling is different), and got tired of switching between both manually, so I whipped up a little python script to toggle php versions:
import shutil;
f = file("C:\Program Files\Apache Group\Apache\conf\httpd.conf")
content = f.read()
php4 = False
if content.find("#LoadModule php4") != -1:
php4 = True
content = content.replace("#LoadModule php4", "LoadModule php4")
content = content.replace("LoadModule php5", "#LoadModule php5")
content = content.replace("#AddModule mod_php4.c", "AddModule mod_php4.c")
content = content.replace("AddModule mod_php5.c", "#AddModule mod_php5.c")
else:
content = content.replace("LoadModule php4", "#LoadModule php4")
content = content.replace("#LoadModule php5", "LoadModule php5")
content = content.replace("AddModule mod_php4.c", "#AddModule mod_php4.c")
content = content.replace("#AddModule mod_php5.c", "AddModule mod_php5.c")
f.close()
f = file("C:\Program Files\Apache Group\Apache\conf\httpd.conf", "w")
f.write(content)
if php4:
shutil.copy("C:\php4\php.ini", "C:\windows\php.ini")
else:
shutil.copy("C:\php\php.ini", "C:\windows\php.ini")
I have php 5 installed in c:\php and php 4 installed in c:\php4 with their respective php.ini files. Hope it can be of some use.


