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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:39:59+00:00 2026-05-23T11:39:59+00:00

I am using the following CURL Multithreading to add multi-threading to PHP processes: function

  • 0

I am using the following CURL Multithreading to add multi-threading to PHP processes:

function multithread_it($url,$threads){
    $started=0;
    while ($started<$threads){
        $ch[$started] = curl_init();
        curl_setopt($ch[$started], CURLOPT_URL, $url);
        curl_setopt($ch[$started], CURLOPT_HEADER, 0);
        curl_setopt($ch[$started], CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch[$started], CURLOPT_RETURNTRANSFER, 0);
        $started++;
        }
    $started=0;
    $mh = curl_multi_init();
    while ($started<$threads){
        curl_multi_add_handle($mh,$ch[$started]);
        $started++;
        }
    $started=0;
    $running=null;
    do {curl_multi_exec($mh,$running);} while($running > 0);
    while ($started<$threads){
        curl_multi_remove_handle($mh, $ch[$started]);
        $started++;
        }
    curl_multi_close($mh);
    ob_flush();
    flush();
    }

This is called using, E.g.

multithread_it($script_dir."script.php",10);

Inside of script.php I have:

for($i=0;$i<10;$i++){
    echo $i."<br />";
    sleep(1);
    ob_flush();
    flush();
    }

But the data stalls. The script that calls multithread_it waits until all scripts have been completed before showing the data which suddenly jumps on the screen.

This is only sample data of a script that actually takes around 10 minutes to run but the very same concept and codes used with flush, ob_flush and the exact function.

Any ideas how I could get the content inside of script.php to show in the parent script as it loads?

  • 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-23T11:40:00+00:00Added an answer on May 23, 2026 at 11:40 am

    Curl is running with multiple threads in downloading multiple urls, but your php code is still single threaded, which means that it will wait for curl to finish before you can act on all of the downloads.

    The closest thing PHP has to threading are the process control functions.: http://www.php.net/manual/en/book.pcntl.php

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

Sidebar

Related Questions

I'm making FQL calls using the following url and then making a curl call.
The following code will retrieve the body content of a url retrieved using CURL
I am using the following PHP proxy: //Store the URL $jURL = $_POST['jURL']; //Store
I'm trying to simply test my RESTful API with cURL. Using the following invocation:
I am using following PHP code to connect to MS Access database: $odb_conn =
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
I'm trying to upload a picture to a specific website using php cURL but
I am trying to post to a REST service using PHP cURL but I'm
I'm using PHP/CURL to automate calls between 2 closely tied code igniter. Code igniter
The first question is how to run a function using the URL, I have

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.