Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7905367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:26:52+00:00 2026-06-03T10:26:52+00:00

I want to run a php script that will send out a bunch of

  • 0

I want to run a php script that will send out a bunch of emails (newsletters) but since it can take a while for that to run I want the user be immediately redirected to a page with a message like “Your newsletters are queued to be sent out.”
So far the header redirects work but they do not cause the redirection until after all the emails get sent. Can I close the connection after sending the redirect so the browser acts on the redirect immediately? I tried stuff like this


ob_start();
ignore_user_abort(true);
header( "refresh:1;url=waitforit.php?msg=Newsletters queued up, will send soon.");
header("Connection: close");
header("Content-Length: " . mb_strlen($resp));
echo $resp;
//@ob_end_clean();
ob_end_flush();
flush();

in various permutations and combinations but to no avail.
I suspect it cannot be done so simply but before I start messing with cron jobs or custom daemons I thought I’d look into this approach.
Thanks

eg like blockhead suggests below, but no luck

ob_start();
ignore_user_abort(true);
header( "refresh:1;url=mailing_done.php?msg=Newsletters queued for sending.");
header("Connection: close");
header("Content-Length: 0" );
//echo $resp;
ob_end_flush();
flush(); 

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:26:53+00:00Added an answer on June 3, 2026 at 10:26 am

    If you want to run script continuously and still want to display some output then, why don’t you use an ajax request to server which can queue mails and still let user continue browsing that page.

    If you don’t want to use this; instead you could use,
    the script runs background even if the user will be redirected to show_usermessage.php page

    <?PHP
        //Redirect to another file that shows that mail queued
        header("Location: show_usermessage.php");
    
        //Erase the output buffer
        ob_end_clean();
    
        //Tell the browser that the connection's closed
        header("Connection: close");
    
        //Ignore the user's abort (which we caused with the redirect).
        ignore_user_abort(true);
        //Extend time limit to 30 minutes
        set_time_limit(1800);
        //Extend memory limit to 10MB
        ini_set("memory_limit","10M");
        //Start output buffering again
        ob_start();
    
        //Tell the browser we're serious... there's really
        //nothing else to receive from this page.
        header("Content-Length: 0");
    
        //Send the output buffer and turn output buffering off.
        ob_end_flush();
        flush();
        //Close the session.
        session_write_close();
    
    
        //Do some of your work, like the queue can be ran here,
        //.......
        //.......
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a PHP script that will run as a cron job
I want to run a php script on christmas that will email my family
I want to run a php script from the command line that is always
I want to run a cron job every minute that will launch a script.
What I want is a function I can run on user input that will
I want to run php or python scripts from eclipse that will create folders
I want to execute a php-script from php that will use different constants and
I need to develop a script using Wordpress PHP that will run with the
I need to call php script from main script that will run in background
I have a series of PHP scripts that I want to run in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.