WordPress.org

Ready to get started?Download WordPress

Forums

how to handle long process? (1 post)

  1. astorm
    Member
    Posted 9 years ago #

    I am planning on a plug-in that will require a significant amount of processing after the user POST the form. I would like to be able to redirect the user to another page while the process is still running. Here's what I had in mind, but the header redirection wouldn't start until the whole script is completed. Any idea? I thought of using exec() to spawn another script, but there would pose some portability issue (unix vs. win32).

    <?php
    ignore_user_abort(TRUE);
    header("Location: http://something.com/somepage.html");
    ob_flush();
    flush();

    // the following is to simulate some long task that will happen...

    $handle = fopen (dirname(__FILE__) . '/data.txt', "w");
    if ($handle) {
    for ($i = 0; $i < 10; $i++) {
    // echo date("Y-M-d G:i:s") . " Try number " . $i . "\r\n";
    fwrite($handle, date("Y-M-d G:i:s") . " Try number " . $i . "<br>\r\n");
    sleep(2);
    }
    fwrite($handle, "Finally done!!!\r\n");
    }
    fclose($handle);

    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.