Zebra_cURL::__construct PHP Method

__construct() public method

Below is the list of default options set by the library when instantiated: - CURLINFO_HEADER_OUT - TRUE; get the last request header; if set to FALSE the "last_request" entry of the "headers" attribute of the object given as argument to the callback function, will be an empty string; - CURLOPT_AUTOREFERER - TRUE; automatically set the Referer: field in requests where it follows a Location: redirect; - CURLOPT_COOKIEFILE - empty string; no cookies are loaded, but cookie handling is still enabled - CURLOPT_CONNECTTIMEOUT - 10; the number of seconds to wait while trying to connect. use 0 to wait indefinitely; - CURLOPT_ENCODING - gzip,deflate; the contents of the "Accept-Encoding:" header; it enables decoding of the response - CURLOPT_FOLLOWLOCATION - TRUE; automatically follow any Location: header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many Location: headers as specified by the value of CURLOPT_MAXREDIRS - see below); - CURLOPT_HEADER - TRUE; get the response header(s); if set to FALSE the "responses" entry of the "headers" attribute of the object given as argument to the callback function, will be an empty string; - CURLOPT_MAXREDIRS - 50; the maximum amount of HTTP redirections to follow; used together with CURLOPT_FOLLOWLOCATION; - CURLOPT_RETURNTRANSFER - TRUE; return the transfer's body as a string instead of outputting it directly; if set to FALSE the "body" attribute of the object given as argument to a callback function will be an empty string; - CURLOPT_SSL_VERIFYHOST - 2; check the existence of a common name in the SSL peer certificate (for when connecting to HTTPS), and that it matches with the provided hostname; see also the {@link ssl} method; - CURLOPT_SSL_VERIFYPEER - FALSE; stop cURL from verifying the peer's certificate (which would most likely cause the request to fail). see also the {@link ssl} method; - CURLOPT_TIMEOUT - 10; the maximum number of seconds to allow cURL functions to execute; - CURLOPT_USERAGENT - A (slightly) random user agent (Internet Explorer 9 or 10, on Windows Vista, 7 or 8, with other extra strings). Some web services will not respond unless a valid user-agent string is provided
public __construct ( boolean $htmlentities = true ) : void
$htmlentities boolean Instructs the script whether the response body returned by the {@link get} and {@link post} methods should be run through PHP's {@link http://php.net/manual/en/function.htmlentities.php htmlentities} function. @return void
return void
    function __construct($htmlentities = true)
    {
        // if the cURL extension is not available, trigger an error and stop execution
        if (!extension_loaded('curl')) {
            trigger_error('php_curl extension is not loaded', E_USER_ERROR);
        }
        // initialize some private properties
        $this->_multi_handle = $this->_queue = false;
        $this->_running = $this->_requests = array();
        // the default number of seconds to wait between processing batches of requests
        // 0 means no waiting, process all requests at once
        $this->pause_interval = 0;
        // the default number of parallel, asynchronous, requests to be processed by the library at all times
        // (unless the "pause_interval" property is greater than 0, case in which it refers to the number of requests
        // to be processed before pausing)
        $this->threads = 10;
        // set the user's preference on whether to run htmlentities() on the response body or not
        $this->_htmlentities = $htmlentities;
        // set defaults for libcurl
        // set defaults
        $this->option(array(CURLINFO_HEADER_OUT => 1, CURLOPT_AUTOREFERER => 1, CURLOPT_COOKIEFILE => '', CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_ENCODING => 'gzip,deflate', CURLOPT_FOLLOWLOCATION => 1, CURLOPT_HEADER => 1, CURLOPT_MAXREDIRS => 50, CURLOPT_TIMEOUT => 30, CURLOPT_USERAGENT => $this->_user_agent(), CURLOPT_RETURNTRANSFER => 1));
        // if PHP version is at least 5.5
        if (version_compare(PHP_VERSION, '5.5') >= 0) {
            // disable usage of @ in POST arguments
            // see https://wiki.php.net/rfc/curl-file-upload
            $this->option(CURLOPT_SAFE_UPLOAD, true);
        }
        // set defaults for accessing HTTPS servers
        $this->ssl();
        // caching is disabled by default
        $this->cache(false);
    }