Jump to content

PHP Dev Environment


kid_drew

Recommended Posts

For those of you who run live active sites, how do you handle code development/testing without potentially breaking a piece of code that your users are interfacing with?  Do you have a whole separate development server and then pass tested code to the live server?  How do you redirect requests to an "updating server" page while you are making software upgrades?

Link to comment
Share on other sites

Until last month I was forced to program on our live site used by our clients, much against my wishes to do so.

 

I created two scripts for handling a "debug" cookie; one script requires a password and creates the cookie, the other deletes the cookie.

 

Next, whenever I wanted to heavily modify a section of our website, I'd copy the original file with an additonal .NEW in the file name.  file.php would become file.NEW.php.  Then, at the top of the old file.php, I'd check for the existence of the debug cookie; if the cookie is set then redirect to the new page, otherwise stay on the old page.

 

I only did this for files that I was heavily modifying and constantly making changes to during an update.  Files that contain libraries or helper functions I didn't bother with since I rarely had a need to change them or the changes were small.  I think this eliminated the majority of instances where I might have introduced a syntax error while an actual user was visiting the same page, preventing them from getting a blank page.

 

I still had to be very careful when modifying the database.  Each of our clients has their own database on our server and I work in a test database.  To make the database changes, I would save all of the queries in a .txt file that I was using to modify the database.  When the update was ready to be applied I'd do a one time application of the queries to all of the existing databases.

 

Much to my happiness, we finally got ourselves a test server.  Both our test and live servers are VPS packages offered by ServerPowered.  Now all of my programming occurs in the hosted test server.  Part of the process of setting up these servers was to write a bunch of shell scripts.  I have scripts that copy a client's database from the live server to the test server for debugging purposes; I also have scripts that copy a client's file data, i.e. the files they've uploaded to the server, from the live server to the test server.  This enables me to more easily try new things in debugging their data and making significant database design changes because I know it won't affect any of our clients if I screw up.

 

The two most important scripts are the ones that synchronize the source code between the servers.  Both of these scripts are run from the test server and modify a file on the live server named sync.lock.  The first script creates sync.lock and enters a timestamp into the file.  On the live server, the entry page checks for the existence of this file; if it exists, a warning is displayed on every page of the site that the site is about to go down for maintenance and everyone should finish up whatever they're working on.  The second script modifies the contents of sync.lock to indicate that a sync is in progress; when the live site detects this content, all users are redirected to a static .html page.  After modifying sync.lock, the second script then creates a local backup of the test server's source code, a remote back up of the live server's test code, a copy of the live servers code on the test server, sends the code over, and then deletes sync.lock.

 

The scripts I've written fall into three groups, those that can be run on only the test server, those that can be run on only the live server, and those that can be run on either.  Every script detects the server it is being run on and exits if the server is inappropriate to the script.

 

Lastly, I still use the debug cookie when making changes on the test server because I still want to test their functionality privately after moving them to the live server, in case there are environmental differences.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.