Sunday, August 2, 2009

Svn, Linux server, XP dev box have different dir structure, how can I make includes system ignorant?

I'm currently developing PHP applications on a Windows XP machine. I test everything locally (Apache 2 %26amp; php 5), but the live web server is linux (also Apache 2 %26amp; php 5).





The files I check out (subversion) use explicit paths (the standard here) that don't translate to my local windows box.





Is there a way to have PHP automatically translate lines like:


%26lt;?php require_once('/www/project1/file.php'); ?%26gt;


to work like:


%26lt;?php require_once('c:/projects/project1/file.... ?%26gt;


without having to manually change everything after each checkout and before each checkin?

Svn, Linux server, XP dev box have different dir structure, how can I make includes system ignorant?
Well, if you can differentiate what system you are running on (e.g. get the hostname or IP and use that to determine if you are in test or prod mode) then you can set paths %26amp; other system dependent data (passwords, logon ids etc).





A better possibility is to write a query to pull that information out of a local database so when your code is in prod it gets the production values and when it is in test it gets test values.





Yet another possibility is to put the values into a require file in the same directory with the code you are writing and import it. However, this may not work for you as it seems your standards do not allow you to say "require_once("./settings.php");"





I have worked on a variety of platforms in a variety of settings and this is always a problem. You try to minimize it but it is often one runs into the need for hardcoding in values that differ between test %26amp; prod.





Oh one more idea. Develop on Linux instead of Windows.


No comments:

Post a Comment