Welcome Guest, Not a member yet? Register   Sign In
Why does a syntax error in a NOT requested controller bring down a whole CI app?
#1

Hey,

So I ran into a situation where a test controller had a stupid syntax error and it brought down the whole app.
This test file was accidentally pushed onto live and brought everything offline..

Now few questions:
1. Why is it that a syntax error in a controller which is NOT requested and not included or anything bring down the whole app?
Are all controllers loaded - always-? I thought CI did lazy loading? Only load what is needed when its needed?

2. Is there anyway we can prevent this ?
(other then obviously making sure testing controller doesn't get pushed to live w/o first checking it on dev)

3. Prob unrelated to CI; but on live we have error reporting turned off via the bootstrap file of course..
However this syntax error was also NOT logged in nginx error logs at all... (using php-fpm) if anybody has any idea about that please do shoot..

Thank you!
Steven
Reply
#2

1. A controller that's not included cannot crash the app. No, not all controllers are loaded, but all base controllers are (e.g. MY_Controller).
2. Pay more attention? Other than that - no, you can't prevent erroneous code from erroring.
3. Of course no errors will be reported if you turn error_reporting Off ... It must never be Off; what you need to do is turn Off display_errors, so that error messages don't get displayed to your users.
Reply
#3

hey,

thanks for your reply.

1. well it did ...
controller was test.php in controllers folder. And every page in the app displayed the syntax error..
That's what is confusing me because what you said is what I knew and assumed.

3. I didn't turn it on on php.ini level but using 'error_reporting(0);'
Reply
#4

1. I highly doubt that. Even if it is possible to happen, it would have nothing to do with CI, but rather with something like PHP's opcache.
3. Nobody said anything about php.ini ... please read carefully. You're not supposed to turn Off error_reporting ever, period.
Reply
#5

(05-28-2017, 11:51 PM)Narf Wrote: 3. Nobody said anything about php.ini ... please read carefully. You're not supposed to turn Off error_reporting ever, period.

I cannot agree/stress this more. I'm dealing with some legacy code that the original developer wrote which is so riddled in errors, porting it to CI has been a huge headache. Turned off errors, all of them, all of the time, even on dev servers.

NEVER do that (not for the OP, for everyone Smile )
Reply
#6

1. hmm interesting so the culprit of this could be APC or xcache.. I believe xcache is installed on this server.
Video proof: https://www.screencast.com/t/BwO7fZTFNoe

2. The error_reporting set to 0 is only done on production environment, of course not on dev.
I'm pretty sure CI even does this out of the box in the bootstrap index.php. I don't think it is a good idea to show any php generated errors on production.. however they SHOULD be logged.
Reply
#7

Dude, seriously ... read what I am saying.

display_errors determines whether errors are being shown, NOT error_reporting.

CodeIgniter turns Off display_errors on production, NOT error_reporting. And this is not by accident - if the errors aren't reported, they cannot be logged. "Reporting" and "displaying" are different things.
Reply
#8

(05-29-2017, 04:23 PM)flechamobile Wrote: 1. hmm interesting so the culprit of this could be APC or xcache.. I believe xcache is installed on this server.
Video proof: https://www.screencast.com/t/BwO7fZTFNoe

Are you sure you're not manually including that file somewhere in your code?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB