CodeJunkie
CodeJunkie

Reputation: 379

PHP: changing code if domain is testing environment

I have 2 droplets on digitalocean. Droplet 1: Live Environment. Droplet 2: Test Environment.

I frequently take a snapshot of a given droplet and rebuild the other droplet with that image (to make sure both servers are setup the same way). Then I'll FTP into the test server and make appropriate changes to lock the domain down.

The Problem: I need to change some php code every time I do this, example changing an api endpoint to it's testing counter part. etc.

I've been thinking I could write some code that will automatically change to test/live based off the domain..

Is this bad? I'm afraid if I have domain dependent code the website could take a performance hit simply because it has to check every time it is run.

Am I going about this the wrong way?

Upvotes: 0

Views: 79

Answers (1)

Thomas
Thomas

Reputation: 1401

Just as ceejayoz said, you need to implement some form of environment variables. One way would be having some form of configuration file that stored the values. You could name the file based on the server and include it when necessary.

But really, just checking what server you're on won't have any real negligible affect as it'd be done once per script execution (and is just a string compare).

Upvotes: 1

Related Questions