title: Asynchronous cURL using POST
body: <p>I am making a <strong>command line</strong> 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.</p>
  
  <p>The chain of events is as follows:</p>
  
  <ol>
  <li>I open cURL connection with curl_init</li>
  <li>I log in to remote site sending POST request with curl_exec and get returned HTML code as response</li>
  <li>I send multiple POST requests to same site simultaneously.</li>
  </ol>
  
  <p>I was thinking of using something like that:</p>
  
  <pre><code>// 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' =&gt; 'username' , 'password' =&gt; '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 &lt; 10 ; $i++){
      $post = array('myvar' =&gt; 'changing_value');
      curl_setopt($ch, CURLOPT_URL, 'www.myweb.ee/changing_url');
      curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
      curl_exec($ch);
  }
  </code></pre>
  
  <p>But this doesn't seem to work as only the first request in loop seems to be sent.</p>
  
  <p>Using <code>curl_multi_init</code> 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.</p>
  
  <p>I don't need any response from server for those simultaneous requests but it would be awesome if it also can be done somehow.</p>
  
  <p>It would be perfect if someone could push me in the right direction how to do it.</p>