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.
This also means you can leave debug set to 2 in your core config file at all times.
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.
2 Comments
blog.cakep...brasil.org
Mar 12th 2009, 04:16
Jul 9th 2009, 15:44
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^^