class CurlWrapper {
	static private $ch;
  function __construct($url)
		self::$ch = curl_init($url); // todo: should set URL later with CURLOPT_URL
    curl_setopt($ch, CURLOPT_VERBOSE, false);
    curl_setopt($ch, CURLOPT_AUTOREFERER, false);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIESESSION, false);
    curl_setopt($ch, CURLOPT_CRLF, false);
    curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, true);
    curl_setopt($ch, CURLOPT_FAILONERROR, false);
    curl_setopt($ch, CURLOPT_NETRC, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_BUFFERSIZE, 16384);  // bigger?
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // Don't verify, 1=verify, 2=verify & match name
    curl_setopt($ch, CURLOPT_SSLVERSION, 3);
    curl_setopt($ch, CURLOPT_TIMEOUT, 0);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Edoceo phps3tk/0.4');
    // Set my CallBack functions
    //curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this,'_curl_head'));
    //curl_setopt($ch, CURLOPT_READFUNCTION, array(&$this,'_curl_read'));
    //curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, '_curl_write'));
    return $ch;

  // func: _curl_header($ch,$buf) - Curl Header Callback
  function _curl_head($ch,$buf)
    // echo "S3Connection::_curl_head($ch,$buf)\n";
    $ret = strlen($buf);
    if (preg_match('/^HTTP\/1\.1 (\d{3}) (.+)/',$buf,$m))
      $this->_status_code = $m[1];
      $this->_status_mesg = $m[2];
                if (preg_match('/^(.+?):(.+)/',$buf,$m)) $this->_head[strtolower(trim($m[1]))] = trim($m[2]);
                // note: HTTP 1.1 (rfc2616) says that 404 and HEAD should not have response.
                // note:  CURL will hang if we don't force close by return 0 here
                // note: http://developer.amazonwebservices.com/connect/thread.jspa?messageID=40930
                // Last Line of Headers
                if (($ret==2) && ($this->_http_request_verb=='HEAD')) return 0;
    return $ret;

Loading Comments from Disqus...