0

I got a plugin that let users send invitations to their friends. If the user have like 4000 friends we run into trouble.

At the moment i use a simple batch like the following for emails. But we also send facebook and twitter messages. USer don't need to wait until procces is complete and this is called actually with a ajax call

set_time_limit(60*60);

if( $quantity < 40 ){

    foreach( $emails as $email )
    {
        wp_mail( $email, $subject, $message, $headers);
        sleep(1);
    }

}
else
{
    $counter = 0;
    //Lets create batches
    foreach( $emails as $email )
    {
            $counter++;
        wp_mail( $email, $subject, $message, $headers);
        sleep(1);

        if( $counter == 50 )
        {
            sleep(10);
            $counter = 0;
        }
    }
}

As cron jobs are usually not allowed in shared hosting, the same way exec sometimes is not available we were thinking on use wp_schedule_single_event. Should be possible or i would need to try a exec("doTask.php $arg1 $arg2 $arg3 >/dev/null 2>&1 &"); approach to run the process in the background?

1 Answer 1

0

If by "run into trouble" you mean that you are getting server or browser timeouts, I'd expect the same trouble with wp_schedule_single_event, since it is just going to run your function at some other time.

I would consider using wp_schedule_event to break the work up into chunks-- say, process 500 (of your 4000 likes) every half-hour or every hour. I suppose you could do the same with wp_schedule_single_event by scheduling multiple single events but I am not sure why you would prefer that over wp_schedule_event.

Neither of those will strictly be "background" processes, though, by which I think you mean something like this.

I should also note that most of the hosts I've seen do not allow the kind of mass volume email that you are sending. I'd check the TOS if you haven't already.

2
  • I think i will end using a big job queue list on the database and run 300 jobs hourly or something like that. What is not very clear to me about wp_schedule is "The action will trigger when someone visits your WordPress site, if the scheduled time has passed"
    – chifliiiii
    Commented Jul 15, 2013 at 14:09
  • wp_cron is not a background process. It is not like system cron that runs on clock time. It is triggered when someone visits the page. That is a limitation of HTTP/Apache/PHP. See: wordpress.stackexchange.com/a/105708/21376
    – s_ha_dum
    Commented Jul 15, 2013 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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