My first guess would be that either the limit for execution time or for memory in PHP is too low on your server. At least for abdagon's problem, as creating statistics for all answers can require quite some resources on the server.
Now when submitting a survey, I am not sure if this is the same problem.
Help us to help you!
Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
Thing is, the survey is logged and submitted OK. The customer even gets the confirmation email saying he successfully submitted the survey and that it was saved. It's just the on screen message after hitting submit is not displayed; the timer just spins for ages and then you get the Gateway Timeout