views:

40

answers:

3

I've developed a PHP web application that is currently in need of a strategic restructuring.

Currently when we setup new clients we give them the entire code base on a subdomain of our main domain and create a new table for them in the database.

This results in each client having the entire codebase, meaning when we make bug changes, fixes we have to go back and apply them independently across all clients and this is a pain.

What I'd like to create is a base code server that holds all the core PHP files. base.domain.com

Then all of our clients (client.domain.com) will only need a few files:

  • config.php would have the database connection information.
  • index.php - displays the login box if session non-existant, otherwise it loads baseline code via remote includes to base.domain.com.

My question is does my logic seem feasible? How do other people handle similar situations by having a base code?

Also.... Is it even possbile to remotely include PHP files from base.domain.com and include them in client.domain.com?

Thanks, Tegan

+1  A: 

Create a clientId for every clients, then you can work in one database and you can deal with config.php, where you define this unique id for every users.

Second question:

PHP.NET http://php.net/manual/en/function.include.php:

If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see List of Supported Protocols/Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.

Roland Soós
I think for this type of application it is better that we keep each client's databases separate because of the corporate data involved. I've just realized instead of including the files remotely I just use the full path to the file on the server. Thanks
Tegan Snyder
+1  A: 

Is it even possbile to remotely include PHP files from base.domain.com and include them in client.domain.com?

It's possible, but dismally slow. Plus, what happens if your central server is offline? All the clients' apps wouldn't run any more.

I don't know what kind of a platform your client's apps run on, but isn't this a job for a version control system like Subversion?

Changes to the code base would get checked in into a central repository, and then all the clients' copies updated automatically.

Pekka
Thanks for your suggestions regarding subversion.
Tegan Snyder
+1  A: 

This results in each client having the entire codebase, meaning when we make bug changes, fixes we have to go back and apply them independently across all clients and this is a pain.

Why not fix this problem instead? Writing a small script to rsync the latest 'stable' build you want published to different clients should be not to time-consuming or error-prone (or use your version-control software to to exactly that).

ChristopheD