I recently had to debug a problem on a production site, so I cloned it to my local computer.
Now, the site was just hanging (loading forever).
Here's how I fixed the problem:
- I first eabled xdebug on my local site.
- Next I installed Webgrind.
- Now I visited the hanging page and add ?XDEBUG_PROFILE=1 to the end of the URL
- Webgrind informed me that lock_wait() was being called repeatedly. Unfortunately I could not find the exact trace and arguments with Webgrind.
- I installed Netbeans, a nice IDE which allows you to set breakpoints on your PHP code, so I set the breakpoint directly on the lock_wait() function (make sure the path to PHP on Netbeans is the same path as what is actually used by the site, in my case /Applications/MAMP/bin/php/php5.4.4/bin/php, not /usr/bin/php). This told me that the lock on "variable_init" was never being released, and that the semaphore table was involved.
- Next, I made sure all my MySQL queries were being logged and inspected the result. Sure enough, the system was repeatedly trying to delete the semaphore entry for variable_init.
- Next, a trip to the command line, drush sqlc, and the following command did the trick:
delete from semaphore where name='variable_init';
Now my site loads fine. I'm not sure if there are side effects to doing this, but in any case my local site is just for debugging purposes and I'll throw it away afterward.