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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:31:55+00:00 2026-05-24T22:31:55+00:00

I have some process in page. It’s downloading a file. <?php // getting file

  • 0

I have some process in page. It’s downloading a file.

<?php

// getting file with CURL
        $ch = curl_init ('http://adress.com/file.csv');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT,7500);
    $rawdata=curl_exec($ch);
    curl_close ($ch);
// End Curl Process

// SAVE FILE
    $name = Rand(100000,1000000);
    $fp = fopen('files/'.$name.'.csv','w');
    fwrite($fp, $rawdata);
    fclose($fp);

// END SAVE PROCESS

// REDIRECT OTHER PAGE
       **header('Location: x.php');**
// END OF PAGE

?>

This is allright. But there is a problem. It redirects without complete process. I want to redirect after all processes are done. The file is empty when i redirect with that method.

What must I do? How can i redirect page after all processes are done? php or javascript/jquery.

  • 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-24T22:31:56+00:00Added an answer on May 24, 2026 at 10:31 pm

    Your code should be fine, and should complete the process before redirecting.

    PHP runs in a single thread, so the next statement won’t be executed until the previous one completes. This means that your header() line won’t execute until fwrite() has finished writing the file.

    In fact, setting a Location header doesn’t even mean the PHP script stops. You can test this by creating a dummy file and running unlink() on it after issuing the Location header. The file will still be deleted. All that Location does is sends a new location to your browser. Your browser then retrieves the new page before the old one is done running.

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

Sidebar

Related Questions

If I have a page that takes some amount of time to process, and
http://www.devx.com/wireless/Article/39101/0/page/2 I have followed this tutorial and got it to work and everything. now
I have console application. In that i have some process that fetch the data
I have to present some 'process' or 'flow' of the application at work on
I have inherited some code: Process p = new ProcessBuilder(/bin/chmod, 777, path).start(); p.waitFor(); Basically,
I have some code that starts a background process for search in my WPF
I have some data generated in MATLAB that I want to process using Perl.
In the process of changing some code, I have spilt some functions into multiple
I have a directory to which a process uploads some .pdf files. This process
I have to manipulate some Excel documents with C#. It's a batch process with

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.