I'm creating a WordPress plugin that will copy posts data to a remote database, I know it will take a while to transfer all the posts.

How should I create copy functionality so it won't timeout? Ideally it would run in background and show some notification on completion.

1 Answer 1


You could use WordPress' pseudo-cron and wp_schedule_single_event.

// add the action.
add_action('wpse71941_cron', 'wpse71941_long_running');
function wpse71941_long_running($args)
    // might need to call `set_time_limit` here

    // do long running stuff here

    // return normal time limit
    if($l = ini_get('max_execution_time'))

// schedule the event for right now
    array('args' => 'for', 'callback' => 'function')

Not sure if you need to mess with time limit. WP does call ignore_user_abort at the top of the cron script.

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.