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 6386691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:03:28+00:00 2026-05-25T03:03:28+00:00

I have a deal where file1.php curl runs file2.php. file2.php is a long running

  • 0

I have a deal where file1.php curl runs file2.php. file2.php is a long running file, but it sends(or is supposed to send) a response back to file1.php then carry on with it’s code. I am using output buffer to try sending this data, but the problem is if I ‘return;’ right after the flush; file1.php receives the response just fine, but when I try to keep file2.php running, file1.php never receives the response, what I am doing wrong? Is there a different way I must send the response back to file1.php?

// file1.php
    $url = "file2.php"

    $params = array('compurl'=>$compurl,'validatecode'=>$validatecode);

    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => true,     // return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "Mozilla", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        CURLOPT_TIMEOUT        => 10,       // don't wait too long
        CURLOPT_POST           => true,     // Use Method POST (not GET)
        CURLOPT_POSTFIELDS     => http_build_query($params)
    );
    $ch = curl_init($url);

    curl_setopt_array( $ch, $options );
    $response = curl_exec($ch); 
    curl_close($ch);
    echo $response;

// file2.php
ob_start();
echo 'Running in the background.';

// get the size of the output
$size = ob_get_length();

header("HTTP/1.1 200 OK"); // I have tried without this
header("Date: " . date('D, j M Y G:i:s e')); // Tried without this
header("Server: Apache"); // Tried without this
header('Connection: close');
header('Content-Encoding: none');
header("Content-Length: $size");
header("Content-Type: text/html"); // Tried without this

// flush all output
ob_end_flush();
ob_flush();
flush();

// If I add return; here file1.php gets the response just fine
// But I need file2.php to keep processing stuff and if I remove the
// return; file1.php never gets a response.
  • 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-25T03:03:28+00:00Added an answer on May 25, 2026 at 3:03 am

    In a normal curl transfer you wouldn’t be able to get the data until the page has completed loading ie. your script is finished. If you want to work with partial data, you should look at CURLOPT_WRITEFUNCTION . This creates a callback which you can use whenever any data is available.

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

Sidebar

Related Questions

Has anyone came across where they have to deal with .truststore file? and knowing
I have a .js file to deal with a dialog box whatever when I
I often have to deal with XML documents that contain namespaced elements, but doesn't
I'm playing with this combine.php file and it looks nice, but I'm wondering if
I have realized that my first question won't be answerable, since php can't deal
I know...SVN. But here is the deal. I have several developers (and some designers)
Here's the deal - I have two files, main.html and processing.php. Within the php
I have a PHP file that spits out a form. I want to call
I have this SQL statment in an ASP file that i to deal with,
I have to deal with text files in a motley selection of formats. Here's

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.