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

  • Home
  • SEARCH
  • 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 7673401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:30:13+00:00 2026-05-31T16:30:13+00:00

I am VERY new to PHP, I’m currently working on a service, part which

  • 0

I am VERY new to PHP, I’m currently working on a service, part which includes short urls, I have everything set up ok using header redirection:

<?php

if (code_exists($code)) {
    // this code gets url for redirect:
    $url_query = mysql_query("SELECT * FROM urls WHERE code = '".$code."'");
    $url = mysql_result($url_query,0,'url');
    $id = mysql_result($url_query,0,'url_id');

    // this code redirects user
    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Thu, 1 Jan 1970 00:00:00 GMT");
    header( "HTTP/1.1 301 Moved Permanently" );
    header( "Location: ".$url );

    // this code executes a function, takes 3 - 4 seconds to return
    $affected = dostuff($id);

} else {
    echo "Code Error: ".$code;
}

?>

The line $affected = dostuff($id); is calling several external API’s and writing the results to a mysql table (often 100+ rows).

The problem is because the external API’s and adding rows takes several seconds, the user has to wait for this before being redirected meaning a bad user experience.

Is there any way that I can build and SEND the headers to the user without the code execution being halted?

Alternatively is there a way to ‘kick off’ another script but pass it the $id parameter?

I would rather avoid using CRON jobs if possible as these confuse the hell out of me :).

Any help greatly appreciated.

  • 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-05-31T16:30:14+00:00Added an answer on May 31, 2026 at 4:30 pm

    There is a write-up on this available here: https://www.zulius.com/how-to/close-browser-connection-continue-execution/

    In short, you need to send headers to tell the browser to close connection, force the HTTP server to send data to the browser, and prevent PHP from timing the script out.

    The downside of this method is that one of your HTTP worker threads is used up serving this request. With enough requests, you could easily run out of worker threads to be able to serve requests. Another way to look at this is if someone wants to attack your server, calling the URL to kick off this process many times as fast as possible will quickly bring your server to its knees.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im very new to php and i have a page with 5 includes located
I'm very new to PHP and I have a small task of displaying a
I am very new to PHP, so far I have been using the following
Very new to JS here. When I write PHP I have no problem assigning
I am very new to magento and currently I am getting PHP Extension curl
I am very new in MySQL & PHP. I have 2 tables like these
I am very new to php and I have a table that displays cases
I am very new to php, and i have search and put together this
I'm very new to PHP. I have a line of code on a server
I'm very very new to PHP, but now I have to help my friend

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.