Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

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.