FreePBX hangs at login

Have you ever clicked on your FreePBX link, get prompted for a password, and then sit staring at your browser “connecting to…” your server forever? Restarting Apache doesn’t work, restarting MySQL doesn’t work, even restarting Asterisk doesn’t work. Meanwhile everything else is running just fine, but you need to restart the entire server before FreePBX starts working again.

I’ve had this problem for a while – from FreePBX 2.3 until 2.8 – and can easily trigger it just by typing the wrong password during login. I know I’m not the only one who’s had this problem and I recently decided to get to the bottom of it. This involved lots of PHP error_log statements; first in config.php, then header.php, then header_auth.php. Then I backed out and started moving into the FreePBX framework, chasing down just where this thing stopped. page.index.php, class.astinfo.php, and finally php-asmanager.php.

In that file there’s a function called wait_response which, yes, waits for a response. From the Asterisk Manager Interface, to be specific. There’s a little loop halfway through that deals with multi-line responses; it’s this loop that repeats indefinitely, waiting for a response that’s never coming.

Why AMI falls over, and how to fix it without a reboot I’m still investigating.