I had a small spot of panic earlier this week when a customer reported that their account page on WonderProxy was timing out. The panic intensified when I was readily able to replicate the issue: the script was timing out, and completely failing to display any account information.

I’ve worked on many poorly performing pages in the past, often to great success: that’s not the source of the panic. My real concern was that there was no reason for the page to take that long to generate. We switched over to generating the account information automatically every hour (after our billing updates) to ensure that those pages would build fast. That was unfortunately a large chunk of code I didn’t want to try to debug quickly.

Fortunately the problem was much more benign: a small infinite loop!
We’ve got a small block of code that determines when a user’s billing period starts and ends. It accepts a start date (that could be some number of months back), calculates an end date, and keeps adding a month until *now* occurs between the start and end dates.

$start = strtotime($startDate); $end = strtotime("+1 month", $start); $now = time(); while (!($start < $now && $end > $now)) { $start = strtotime("+1 month", $start); $end = strtotime("+1 month", $start); }

When the account in question was configured (tragically, by me) the start date was set in the future. So my loop obligingly kept looking forever.

A quick database tweak later and the user’s account was fixed, and I had a few sanity checks to add.

Comments »

No Trackbacks
No comments

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

Hi, I’m Paul Reinheimer, a developer working on the web.

I co-founded WonderProxy which provides access to over 200 proxies around the world to enable testing of geoip sensitive applications. We've since expanded to offer more granular tooling through Where's it Up

My hobbies are cycling, photography, travel, and engaging Allison Moore in intelligent discourse. I frequently write about PHP and other related technologies.