The general rule of thumb for non-realtime tasks (biggest example being, sending emails) these days is to drop the task onto a queue, to be picked up by a "queue-runner" and processed, as to give the end user the fastest browsing experience.
As an example, see Laravel's Queue system, where the main example is sending emails.
I've been dealing with a growing issue that's become really noticeable over the last 6-9 months, where posting replies to topics can be very slow. It appears the c