It's got to be something on the PHP side of things since nothing even starts rendering in the browser until the very end of that 55 seconds. I would add debug statements (that print out the time) throughout the gallery page so you can narrow down what part of the code is taking that long to execute. If it points to a function call, then add debug statements in that file and so on.
-justin