if it's "only" a 522-Error that means, that the request can't be handeled.
Mainly that's because of one of the following problems:
* the server is totally overloaded, so that he can't answer fast enough (not enough io, ram, etc. so swapping, timeouts etc.)
* your script is bogus and creates queries, that are longer than the php-settings definied in your webspace(?)
* your php / mysql / whatever-config is somehow messed up