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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:34:50+00:00 2026-05-27T09:34:50+00:00

My php script downloads files from a remote server using cURL. I wanted to

  • 0

My php script downloads files from a remote server using cURL. I wanted to monitor the bandwidth that was being used when downloading the file so what I did was put an SQL update query within the write_callback function. This works like a charm but im worried that the database will have troubles if a script like this is updating data every 10 miliseconds or so. Does cURL have a “completed” call back function? so that the script will collect the amount of bytes that were downloaded then update ONLY once when its been completed? And also does the cURL have some type of interruption callback or incomplete? so when users kill the download it somehow recognizes that and subtracts the bytes that were downloaded in the process.

  • 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-27T09:34:51+00:00Added an answer on May 27, 2026 at 9:34 am

    You could do something like this:

    $ch = curl_init($url);
    
    // ... set whatever options you need
    
    curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
      global $bytes;
      $bytes += strlen($data);
      // Write data here
    });
    
    $bytes = 0;
    $starttime = microtime(TRUE);
    
    curl_exec();
    
    $endtime = microtime(TRUE);
    $totaltime = $endtime - $starttime;
    
    // You would do your DB update here
    echo "Downloaded $bytes bytes in $totaltime seconds (".($bytes / $totaltime)." bytes/second)";
    

    Handling interupts would be more difficult, but maybe you could use register_shutdown_function()? I don’t know if this actually gets called when the script receives SIGINT, though. You may also be able to use pcntl_signal() if it is available.

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

Sidebar

Related Questions

I'm writing a PHP script that downloads a series of generated files (using wget
I need to download files from remote server with my PHP script. The problem
I have a PHP script that needs to download several files from a remote
I'm using a php script to download large files from a server and then
I've written a PHP script that handles file downloads, determining which file is being
I've created a script that downloads very large files from the internet. Something quite
I need a simple proxy PHP function/script that can download a file from a
I have created a PHP-script to update a web server that is live inside
I have a php script, which downloads, rescales and stores an image using the
Hey everyone, I have written a script that downloads a zip file from 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.