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?