WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm calling a custom function when someone submits comments using the following to plug into the comment_post action: add_action('comment_post', 'MY_FUNCTION');

The problem is that my function is extremely heavy, causing about a 5 second delay between the time when someone submits a comment to the time when the page refreshes and they view their comment. Is there any way that my custom function could run in the background, so that they could be redirected right away? Alternatively, would it be safe to redirect them directly at the top of my function, then run the rest of my function after they had already been redirected?

share|improve this question
up vote 2 down vote accepted

If you're sending a redirect, then you can also just close the connection early and continue processing.

header("Content-Length: 0");
header("Connection: close");
do_something(); // continue processing whatever, user is already redirecting by now

Reference: http://www.php.net/manual/en/features.connection-handling.php#104541

Read those user comments carefully, there's some caveats there.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.