Q: How can i get the response of a server using cURL with php? I have a sender script and a receiver script. The sender sends an xml file , while the receiver gets it and stores it in the database.
The sender looks like this :
$xml = file_get_contents("data.xml");

  // We send XML via CURL using POST with a http header of text/xml.
  $ch = curl_init();
  // set URL and other appropriate options
  curl_setopt($ch, CURLOPT_URL, "http://localhost/iPM/receiver.php");
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  curl_setopt($ch, CURLOPT_REFERER, 'http://localhost/iPM/receiver.php');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $ch_result = curl_exec($ch);
  echo "Result = ".$ch_result;
  curl_close($ch);

and the receiver :
$xml = file_get_contents('php://input');

parsing the xml - storing to database
etc etc etc etc etc etc etc etc etc

I need when i run the sender script , to get back a response from the receiver that everything was ok and the xml file was received. I believed that i would see that with this line of code , in my code :  echo "Result = ".$ch_result;  but the only thing i see printed is Result = .
So what am i doing wrong? What should i add on my sender/receiver to have a response back?

A: Replace the following lines:
$ch_result = curl_exec($ch);
echo "Result = " . $ch_result;

with the following lines and see if it works:
$ch_result = curl_exec($ch);
$ch_header = curl_getinfo($ch);
echo "Status : " . $ch_header['http_code'] . "<br />";
echo "Result = " . $ch_result;

The curl_getinfo return basic information about the request and the http_code variable returns the response code 200,404 etc. You can then check for the code and parse it as per your requirements.
Hope it helps.
