Dealing with conflicts caused by replication in BigCouch

Get the revision number of the document to be updated if there is a conflict during attachment and recursively call in-case of a conflict,

$url = "http://couchdb/DATABASE/DOCID/ATTACHMENTNAME?rev=$rev";
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_PUT, true );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_exec( $ch );