title: CURLOPT_COOKIE is cause a timeout
body: <p>I'm trying to pass php curl the current logged in session (so I don't have to log in with curl before sending form data).</p>
  
  <p>Seems like no matter what I try CURLOPT_COOKIE causes the page to timeout:</p>
  
  <pre><code>function postForm($post_data, $URL) {
      //traverse array and prepare data for posting (key1=value1)
      foreach ( $post_data as $key =&gt; $value) {
          $post_items[] = $key . '=' . $value;
      }
  
      //create cURL connection
      $curl_connection = curl_init($URL);
  
      //set curl to current session
      //$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
      //$strCookie = session_name() . '=' . session_id());
      $strCookie = 'PHPSESSID=' . session_id() . '; path=/';
      $useragent = $_SERVER['HTTP_USER_AGENT'];
  
      //set curl options
      curl_setopt($curl_connection, CURLOPT_USERAGENT,$useragent);
      curl_setopt($curl_connection, CURLOPT_COOKIE,$strCookie); 
      curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 60);
      curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
          ...
  
  
  //create the final string to be posted using implode()
  $post_string = implode ('&amp;', $post_items);
  
  //set data to be posted
  curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
  </code></pre>
  
  <p>Line <code>curl_setopt($curl_connection, CURLOPT_COOKIE,$strCookie);</code> is causing the script execution to timeout.</p>
  
  <p>How can I pass <code>cUrl</code> the current session so it does not need to login to post a form?</p>
  
  <p>edit (more info):
  curl_getinfo() shows 500 http_code error when it times out.</p>
  
  <p>edit: </p>
  
  <p>Well I still can't get this to work. I can send the form fine in the POSTMAN REST Client Chrome extension, but I can't figure out how to do this with curl.</p>
  
  <p>I tried CURLOPT_COOKIEFILE/CURLOPT_COOKIEJAR like this, but it still didn't work:</p>
  
  <pre><code>$useragent = $_SERVER['HTTP_USER_AGENT'];
  $tmp_fname = tempnam("/tmp", "COOKIE");
  
  //set curl options
  ...
  curl_setopt($curl_connection, CURLOPT_COOKIEJAR, $tmp_fname);
  curl_setopt($curl_connection, CURLOPT_COOKIEFILE, $tmp_fname);
  ...
  </code></pre>
  
  <p>If it helps here is how I sent it with POSTMON, seems pretty straight forward, don't know why I can't get it working with curl:
  <img src="https://i.stack.imgur.com/nRNVr.png" alt="enter image description here"></p>
  
  <p>edit: more info
  When I check the IIS logs I can see a difference between the two requests. The first one is with php and the second, working one, is with POSTMON:</p>
  
  <pre><code>2014-04-17 22:31:44 ::1 POST /mysite/categories.php ccsForm=categories_maint 80 - ::1 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/33.0.1750.154+Safari/537.36 200 0 64 109717
  2014-04-17 22:34:21 SERVERS.IP.ADDRESS.HERE POST /mysite/categories.php ccsForm=categories_maint 80 - MY.IP.ADDRESS.HERE Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/33.0.1750.154+Safari/537.36 302 0 0 62
  </code></pre>
  
  <p>It looks like with PHP its trying to send the request from itself? Could this be the problem?</p>