CodeSOD: A Graceful Exit

Kaci had one of "those" co-workers who didn't believe in source control. As you modified code, you'd just comment out bits and pieces, maybe replace some of it. That way you could see how the code evolved without having to learn how to use git log correctly.

At least, that was the rough argument. But it meant that when Kaci wanted to understand why this block of PHP code existed, she needed to ask the developer:

//$_GET['debug'] = TRUE; //exit; if (rand(1,20) != 4) { //echo 'im out!'; exit; }

So this code generates a random number between one and twenty, and if it isn't four, exits. Why? Well, the offending developer had an explanation.

"This PHP script runs as part of a cronjob. Instead of editing the crontab to change the schedule, I wanted to be able to change the schedule in code. This is how I ensure it only runs with a specific frequency."

This left Kaci burdened with even more questions than when she started. But at least now she understood why her client-side requests for data served up by that PHP were failing almost all the time.

[Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published.