<?php 
function _doPostRequest($url, $data, $optional_headers = null) {
    $params = array('http' => array(
        'method' => 'POST',
        'content' => $data
    ));
    if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);
    $fp = @fopen($url, 'rb', false, $ctx);
    if (!$fp) {
        echo "Error: can't access URL \"$url\".".PHP_EOL." --> $php_errormsg.";
    }
    $response = @stream_get_contents($fp);
    if (!$response) {
        echo "Error: can't read response data from \"$url\".".PHP_EOL." --> $php_errormsg";
    }
    return $response;
}
 ?>