S
S
Sonic_SE2011-03-19 16:25:00
Zend Framework
Sonic_SE, 2011-03-19 16:25:00

Testing, staging, production and Zend Framework?

What is the best/easiest way to switch settings on different environments?
Upd: Zend documentation advises APPLICATION_ENV.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly, 2011-03-19
@taliban

php.net/manual/en/function.getenv.php
store here.

Z
zizop, 2011-03-19
@zizop

To store the name of the environment, use an environment variable, as said here. For example "APPLICATION_ENV".
To determine the environment environment, you can use the following algorithm:

$test_domain = 'testsite.ru'; // домен тестового сервера
if(strpos($_SERVER['HTTP_HOST'], $test_domain) !== FALSE) {
$app_env = 'test';
} else {
$app_env = ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']) ? 'development' : 'production';
}
define('APPLICATION_ENV', $app_env ? $app_env : 'production');


To determine if an application is under unit testing, you can use this technique:
public static function isUnderUnitTest()
{
return $_SERVER['PHP_SELF'] === '/usr/bin/phpunit';
}

S
slang, 2011-03-19
@slang

Zend advises this for a reason, the calculation here is that you correctly (according to Zend's advice) set up virtual hosts, such as Apache. Then the code will be universal, and without hardcoded domain names. This is how it looks like (ZendTool also creates something similar):

<VirtualHost hostname.local:80>
  ServerAdmin [email protected]
  SetEnv APPLICATION_ENV "development"
  ServerName hostname.local
  DocumentRoot /home/hostname.local/htdocs
  <Directory />
    Options FollowSymLinks
  </Directory>
  <Directory /home/hostname.local/htdocs/>
    Options Indexes FollowSymLinks MultiViews
    Order allow,deny
    allow from all
  </Directory>
  ErrorLog /var/log/apache2/error.log
  LogLevel warn
  CustomLog /var/log/apache2/access.log combined
</VirtualHost>

Pay attention to line 3. This sets the environment variable for the host, and in the case when the universal code is deployed to this host, it works in "development" mode. Naturally, production and others have their own virtual host configs, and by default the code works in production mode. This is Zend's idea, of course you can fence your own garden, although, as it seems to me from experience, this one is the most convenient.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question