Depending on how much spam is being cleaned or the actions taken, it might take a little while to run the spam cleaner. You may need to look at increasing the timeout between your web server/proxy and PHP-running server (PHP-FPM?). Alternatively, it could be related to the task being extra slow due to a high load issue (thus making everything significantly slower).