[wp-hackers] Closing the HTTP connection on wp-cron

David Anderson david at wordshell.net
Fri Apr 12 09:50:38 UTC 2013


Hi,

I author a backup plugin, and on one site I'm looking at, we've run into 
an issue with Cloudflare.

Basically, all scheduled backup plugins are using WordPress's scheduler, 
and by default this is using wp_remote_post to post to itself.

When the site is behind Cloudflare (which is just an enormous reverse 
proxy), Cloudflare times out after 30 seconds. This makes the the 
backups run a lot slower; or on really large sites which are 
resource-starved, makes them time out. On the particular one I'm looking 
at, 30 seconds is worth about 12 seconds on an average host. Not enough 
time for the backup engine to restart, scan through a big zip file to 
see what files are already in there, and then scan through more files to 
add, and actually add a new batch before Cloudflare kills the

Obviously the best solution is "don't have a really large site on 
resource-starved hosting". But, I'm trying to maximise the odds and want 
to see what more I can do.

The backup plugin doesn't need to send any output when it's doing a 
backup job via cron. There's nowhere for the output to go. So I think 
that I can just close the HTTP connection, when running via cron. So, 
questions:

1) Are there any obvious flaws in that scheme, or a better way to 
achieve the goal?

2) Is this the best way to do that? Google shows quite a lot of 
variations. I've done some HTTP-closing in the past, which has worked, 
and generally use the following - but is it missing anything?

   header("Content-Length: 0");
   header('Connection: close');
   flush();

Many thanks,

David

-- 
WordShell - WordPress fast from the CLI - www.wordshell.net



More information about the wp-hackers mailing list