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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:05:31+00:00 2026-06-12T19:05:31+00:00

I am making a command line application. I need to send out multiple POST

  • 0

I am making a command line application. I need to send out multiple POST requests via cURL simultaneously after I have performed log in procedures – meaning outgoing requests must send session id etc.

The chain of events is as follows:

  1. I open cURL connection with curl_init
  2. I log in to remote site sending POST request with curl_exec and get returned HTML code as response
  3. I send multiple POST requests to same site simultaneously.

I was thinking of using something like that:

// Init connection

$ch = curl_init();

// Set curl options

curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);

// Perform login

curl_setopt($ch, CURLOPT_URL, "http://www.mysite/login.php");
$post = array('username' => 'username' , 'password' => 'password');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$result = curl_exec($ch);

// Send multiple requests after being logged on

curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1);

for($i = 0 ; $i < 10 ; $i++){
    $post = array('myvar' => 'changing_value');
    curl_setopt($ch, CURLOPT_URL, 'www.myweb.ee/changing_url');
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    curl_exec($ch);
}

But this doesn’t seem to work as only the first request in loop seems to be sent.

Using curl_multi_init would probably one solution but I don’t know if i can pass it the same cURL handle multiple times with changed options for each.

I don’t need any response from server for those simultaneous requests but it would be awesome if it also can be done somehow.

It would be perfect if someone could push me in the right direction how to do it.

  • 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-06-12T19:05:32+00:00Added an answer on June 12, 2026 at 7:05 pm

    You’ll need to create a new curl handle for every request, and then register it with http://www.php.net/manual/en/function.curl-multi-add-handle.php

    here is some code i ripped out and adapted from my code base, have in mind that you should add error checking in there.

    function CreateHandle($url , $data) {
        $curlHandle = curl_init($url);
    
        $defaultOptions = array (
            CURLOPT_COOKIEJAR => 'cookies.txt' ,
            CURLOPT_COOKIEFILE => 'cookies.txt' ,
    
            CURLOPT_ENCODING => "gzip" ,
            CURLOPT_FOLLOWLOCATION => true ,
            CURLOPT_RETURNTRANSFER => true ,
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => $data
        );
    
        curl_setopt_array($curlHandle , $defaultOptions);
    
        return $curlHandle;
    }
    
    function MultiRequests($urls , $data) {
        $curlMultiHandle = curl_multi_init();
    
        $curlHandles = array();
        $responses = array();
    
        foreach($urls as $id => $url) {
            $curlHandles[$id] = CreateHandle($url , $data[$id]);
            curl_multi_add_handle($curlMultiHandle, $curlHandles[$id]);
        }
    
        $running = null;
        do {
            curl_multi_exec($curlMultiHandle, $running);
        } while($running > 0);
    
        foreach($curlHandles as $id => $handle) {
            $responses[$id] = curl_multi_getcontent($handle);
            curl_multi_remove_handle($curlMultiHandle, $handle);
        }
        curl_multi_close($curlMultiHandle);
    
        return $responses;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a command-line c++ application and I want text to be on
Making my PHP Command line application support Linux and Windows. Currently it has this
I am making a command line utility. I need to pass around a few
I have an application composed of a GUI and 3 launchd daemon launched command-line
In my application I am making a custom command line. I am looking for
I have made an application in Visual C++ (That uses the command line). I
Currently I'm making sort of SQL command line interface for web-based application. It should
I am developing a Java command line application and I need to display an
I'm making a command-line based tool in Java, and I was thinking I might
I am making a command line program in C using XCode. When running the

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.