Uploader

An all around general purpose file uploader for CakePHP. Packaged as a stand alone plugin with file validation, file scanning and support for a wide range of basic mime types.

Turning debug off automatically in production

Thursday, March 12th 2009, 2:53am
Topics: Tutorials, CakePHP
Tags: Debug, Production, Environment
Comments: 2
Permalink - Tinylink

Update: This entry is incorrect, please refer to this new entry.

So I recently got tired of having to manually set debug to 0 every time I updated an old site or published a new one. So I thought, why not have it automatically turn off when the site is live? For this to work, I'm assuming that you are working on a localhost with an IP of 127.0.0.1. If you are not, you might get this to work by changing the IP in the code below, or using HTTP_HOST instead of REMOTE_ADDR. Simply add this code at the top of your app/config/bootstrap.php file.

// Production
if (env('REMOTE_ADDR') != '127.0.0.1') {
	Configure::write('debug', 0);
}

// Or alternate technique
if (env('HTTP_HOST') != 'localhost') {
	Configure::write('debug', 0);
}


This also means you can leave debug set to 2 in your core config file at all times.
Related Entries:

2 Comments

10 / 2 = ?
Allowed: [code] [b] [i] [u]
  • Juan Basso
    blog.cakep...brasil.org
    Mar 12th 2009, 04:16
    1 Nice. If you see the bakery repository, they use this, but checking if host equals to bakery.cakephp.org to disable debug (reverse logic).
  • mark
    Jul 9th 2009, 15:44
    2 i would do it the other way around!
    as 0 is and should be the default setting

    but other than that :) nice to know somebody else had the same i idea i had months ago^^