PUT 204 status - cURL PHP

Occasional Participant

PUT 204 status - cURL PHP

I was hoping someone could help me out here. I have a php script using cURL to GET, POST, and PUT. Per the documentation a PUT should return a 204 status. My problem is that the api (or my code) seems to be a hit and miss thing. My PUT works one minute and the next it does not. How can I check for a true 204 (successful) PUT? I have tried to check for a !$response from the curl_exec but this triggers my code regardless of whether it was successful or not. here is my code..
$request = $ccuri;
$session = curl_init($request);
$userNamePassword = $usrpsw;
curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
curl_setopt($session, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($session, CURLOPT_CUSTOMREQUEST,"PUT");
curl_setopt($session, CURLOPT_POSTFIELDS , $entry);
curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($session, CURLOPT_HEADER, 0);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($session, CURLOPT_HTTP_VERSION, 1.0);
$response = curl_exec($session);

if(!$response) {return true;}
else {return false;}

I have tried to use
$status = array();
preg_match('/HTTP\/.* (+) .*/', $response, $status);
if ($status = 204) { return true; }

but actually I get no response even when it works.

Can I suggest adding some PUT examples up on the site. You have each kind of example except PUT.

re: PUT 204 Status -> PUT Example (PHP)

Short Put example posted in the Getting Started/Samples Forum here.
Tom M
Group Product Manager – Content Editing
Constant Contact
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More