The error is a symptom, not the problem itself. Same as with medical symptoms you need to address the cause and not numb the symptom.
In this case you need to figure out what script is running so long, PHP really shouldn't even run for more than a couple of seconds (in fact, even a script that takes a second to run is considered "slow").
See if the error log gives you any indication as to what url is being accessed when the error occurs.
Looks like it's timing out on communicating with Gravatar.com.
You should probably report this as a bug here on XenForo, because the software should set a timeout for the request that doesn't exceed the global timeout, so errors like this can be handled gracefully.
The url in the log you posted is cut off, could you post the full url (strip sensitive information)?