Curl
        
        extends Base
    
    
            
            in package
            
        
    
    
            
            Uses
                            EventEmitter                    
    
        
            Curl, an HTTP/FTP response object Simplifies asynchronous requests & paralell downloads.
Uses the cURL functions and throws exceptions on errors.
Table of Contents
- $connect_time : mixed
 - $content_length_download : mixed
 - $content_length_upload : mixed
 - $content_type : mixed
 - $defaults : array<string|int, mixed>
 - Sane defaults for Curl requests. Only used in the static helper methods like Curl::get(), Curl::post(), etc.
 - $effective_url : string
 - $filetime : mixed
 - $header_out : mixed
 - $header_size : mixed
 - $http_code : string
 - $keepalive : bool
 - Keep the connections open, speeds up requests to the same server.
 - $maxConcurrent : int
 - The maximum number of concurrent downloads.
 - $namelookup_time : mixed
 - $onAbort : Closure
 - $onLoad : Closure
 - $pretransfer_time : mixed
 - $redirect_time : mixed
 - $request_size : mixed
 - $requests : array<string|int, Curl>
 - Global queue of active cURL requests.
 - $size_download : mixed
 - $size_upload : mixed
 - $speed_download : mixed
 - $speed_upload : mixed
 - $ssl_verifyresult : mixed
 - $starttransfer_time : mixed
 - $total_time : mixed
 - $events : array<string|int, mixed>
 - Allow listening to the events: 'load' and 'abort'.
 - $__kvo : array<string|int, mixed>
 - Storage array for the properties with KVO (Key Value Observer) listeners.
 - $handle : resource
 - cURL handle.
 - $options : array<string|int, mixed>
 - All the given CURLOPT_* options.
 - $pool : resource
 - cURL multi handle.
 - $state : string
 - RUNNING | COMPLETED | ABORTED | ERROR.
 - $tranferCount : int
 - Number of tranfers in the pool.
 - __call() : mixed
 - Report that the $method doesn't exist.
 - __callStatic() : mixed
 - Report that the $method doesn't exist.
 - __construct() : mixed
 - Create a new cURL request/response.
 - __destruct() : mixed
 - Complete the transfer and remove the curl handle from the pool.
 - __get() : mixed
 - Access CURLINFO_* info as properties.
 - __set() : mixed
 - Report that $property doesn't exist and set the property to the given $value.
 - __toString() : string
 - Returns the response body.
 - abort() : mixed
 - Abort the current request/download.
 - delete() : Curl
 - Preform an asynchonous DELETE request.
 - download() : Curl
 - Download a file to the filesystem.
 - file() : CURLFile
 - Create a file value for use in CURLOPT_POSTFIELDS.
 - get() : Curl
 - Preform an asynchonous GET request.
 - getBody() : string
 - Return the response body.
 - getContent() : string
 - The response body.
 - getHeader() : string|null
 - Get the value of a specific response header.
 - getHeaders() : array<string|int, mixed>
 - Get all response headers.
 - getInfo() : mixed
 - Get information about the response.
 - hasEvent() : bool
 - Check id the $event is a registered event.
 - isComplete() : bool
 - Check if this request is complete.
 - off() : mixed
 - Remove a callback from an event.
 - on() : string
 - Add a callback for an event.
 - post() : Curl
 - Preform an asynchonous POST request.
 - proxy() : mixed
 - Proxy/resend the current request to different url/server.
 - put() : Curl
 - Preform an asynchonous PUT request.
 - putFile() : Curl
 - Preform an asynchonous PUT request.
 - resend() : mixed
 - Reuse the curl handle/connection to (re)send an request Use the options to override settings from the previous request.
 - synchronize() : mixed
 - Wait for all requests to complete.
 - trigger() : mixed
 - Trigger an event.
 - waitForCompletion() : mixed
 - Wait for the request to complete.
 - defaults() : array<string|int, mixed>
 - Merge options with the default options.
 - errorName() : string
 - Convert a CURLE_* integer to the constantname.
 - multiErrorName() : string
 - Convert a CURLM_* integer to the constantname.
 - optionName() : string
 - Convert a CURLOPT_* integer to the constantname.
 - start() : mixed
 - Start the request 1. Set the CURLOPT_* options 2. Add the request to the pool 3. Starts the request.
 - stop() : mixed
 - Remove the request from the pool.
 - throttle() : mixed
 - Limit the number of active transfers.
 
Properties
$connect_time read-only
    public
        mixed
    $connect_time
    
        Time in seconds it took to establish the connection
$content_length_download read-only
    public
        mixed
    $content_length_download
    
        content-length of download, read from Content-Length: field
$content_length_upload read-only
    public
        mixed
    $content_length_upload
    
        Specified size of upload
$content_type read-only
    public
        mixed
    $content_type
    
        Content-Type: of the requested document, null: indicates server did not send valid Content-Type: header
$defaults
Sane defaults for Curl requests. Only used in the static helper methods like Curl::get(), Curl::post(), etc.
    public
    static    array<string|int, mixed>
    $defaults
     = array(
    CURLOPT_FAILONERROR => true,
    // Report an error when the HTTP status >= 400.
    CURLOPT_RETURNTRANSFER => true,
    // Don't stream the contents to the output buffer.
    // Automaticly disabled in safe mode
    CURLOPT_FOLLOWLOCATION => true,
    // When allowed follow 301 and 302 redirects.
    CURLOPT_MAXREDIRS => 25,
)
        Only set options you need on EVERY request. A (Charles) proxy for example. Curl::$defaults[CURLOPT_PROXY] = "127.0.0.1"; Curl::$defaults[CURLOPT_PROXYPORT] = 8888;
$effective_url read-only
    public
        string
    $effective_url
    
        Last effective URL
$filetime read-only
    public
        mixed
    $filetime
    
        Remote time of the retrieved document, if -1 is returned the time of the document is unknown
$header_out read-only
    public
        mixed
    $header_out
    
        The request string sent. For this to work, add the CURLINFO_HEADER_OUT option to the handle by calling curl_setopt()
$header_size read-only
    public
        mixed
    $header_size
    
        Total size of all headers received
$http_code read-only
    public
        string
    $http_code
    
        Last received HTTP code
$keepalive
Keep the connections open, speeds up requests to the same server.
    public
    static    bool
    $keepalive
     = true
    
    
    
$maxConcurrent
The maximum number of concurrent downloads.
    public
    static    int
    $maxConcurrent
     = 64
    
    
    
$namelookup_time read-only
    public
        mixed
    $namelookup_time
    
        Time in seconds until name resolving was complete
$onAbort write-only
    public
        Closure
    $onAbort
    
        Event fires when the request has been aborted. For instance, by invoking the abort() method.
$onLoad write-only
    public
        Closure
    $onLoad
    
        Event fires when the request has successfully completed.
$pretransfer_time read-only
    public
        mixed
    $pretransfer_time
    
        Time in seconds from start until just before file transfer begins
$redirect_time read-only
    public
        mixed
    $redirect_time
    
        Time in seconds of all redirection steps before final transaction was started
$request_size read-only
    public
        mixed
    $request_size
    
        Total size of issued requests, currently only for HTTP requests
$requests
Global queue of active cURL requests.
    public
    static    array<string|int, Curl>
    $requests
     = []
    
    
    
$size_download read-only
    public
        mixed
    $size_download
    
        Total number of bytes downloaded
$size_upload read-only
    public
        mixed
    $size_upload
    
        Total number of bytes uploaded
$speed_download read-only
    public
        mixed
    $speed_download
    
        Average download speed
$speed_upload read-only
    public
        mixed
    $speed_upload
    
        Average upload speed
$ssl_verifyresult read-only
    public
        mixed
    $ssl_verifyresult
    
        Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
$starttransfer_time read-only
    public
        mixed
    $starttransfer_time
    
        Time in seconds until the first byte is about to be transferred
$total_time read-only
    public
        mixed
    $total_time
    
        Total transaction time in seconds for last transfer
$events
Allow listening to the events: 'load' and 'abort'.
    protected
        array<string|int, mixed>
    $events
     = array(
    'load' => [],
    // Fires when the request has completed
    'abort' => [],
    // Fires when the request was aborted
    'closed' => [],
    // Fires when the curl handle is closed,
    'error' => [],
)
    
    
    
$__kvo
Storage array for the properties with KVO (Key Value Observer) listeners.
    private
        array<string|int, mixed>
    $__kvo
     = []
    
    
    
$handle
cURL handle.
    private
        resource
    $handle
    
    
    
    
$options
All the given CURLOPT_* options.
    private
        array<string|int, mixed>
    $options
     = []
    
    
    
$pool
cURL multi handle.
    private
    static    resource
    $pool
    
    
    
    
$state
RUNNING | COMPLETED | ABORTED | ERROR.
    private
        string
    $state
    
    
    
    
$tranferCount
Number of tranfers in the pool.
    private
    static    int
    $tranferCount
     = 0
    
    
    
Methods
__call()
Report that the $method doesn't exist.
    public
                __call(string $method, array<string|int, mixed> $arguments) : mixed
    
        Parameters
- $method : string
 - $arguments : array<string|int, mixed>
 
Return values
mixed —__callStatic()
Report that the $method doesn't exist.
    public
            static    __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
    
        Parameters
- $method : string
 - $arguments : array<string|int, mixed>
 
Return values
mixed —__construct()
Create a new cURL request/response.
    public
                __construct([array<string|int, mixed> $options = [] ]) : mixed
    
        Parameters
- $options : array<string|int, mixed> = []
 - 
                    
The CURLOPT_* request options
 
Tags
Return values
mixed —__destruct()
Complete the transfer and remove the curl handle from the pool.
    public
                __destruct() : mixed
    
    
    
        Return values
mixed —__get()
Access CURLINFO_* info as properties.
    public
                __get(string $property) : mixed
    
        Parameters
- $property : string
 
Return values
mixed —__set()
Report that $property doesn't exist and set the property to the given $value.
    public
                __set(string $property, mixed $value) : mixed
    
        Parameters
- $property : string
 - $value : mixed
 
Return values
mixed —__toString()
Returns the response body.
    public
                __toString() : string
    
    
    
        Return values
string —abort()
Abort the current request/download.
    public
                abort() : mixed
    
    
    
    Tags
Return values
mixed —delete()
Preform an asynchonous DELETE request.
    public
            static    delete(string $url[, array<string|int, mixed> $options = [] ][, Closure|callable $callback = null ]) : Curl
    
        Parameters
- $url : string
 - $options : array<string|int, mixed> = []
 - 
                    
Additional CURLOPT_* options
 - $callback : Closure|callable = null
 - 
                    
The callback for the load event.
 
Return values
Curl —Response
download()
Download a file to the filesystem.
    public
            static    download(string $url, string $filename[, array<string|int, mixed> $options = [] ][, bool $async = false ]) : Curl
    
        Parameters
- $url : string
 - $filename : string
 - $options : array<string|int, mixed> = []
 - $async : bool = false
 
Tags
Return values
Curl —file()
Create a file value for use in CURLOPT_POSTFIELDS.
    public
            static    file( $filename[,  $mimetype = null ][,  $postname = null ]) : CURLFile
    
        Parameters
Tags
Return values
CURLFile —get()
Preform an asynchonous GET request.
    public
            static    get(string $url[, array<string|int, mixed> $options = [] ][, Closure|callable $callback = null ]) : Curl
    
        Parameters
- $url : string
 - $options : array<string|int, mixed> = []
 - 
                    
Additional CURLOPT_* options
 - $callback : Closure|callable = null
 - 
                    
The callback for the load event.
 
Return values
Curl —Response
getBody()
Return the response body.
    public
                getBody() : string
    
    
    
        Return values
string —getContent()
The response body.
    public
                getContent() : string
        (If the CURLOPT_RETURNTRANSFER option is set).
Return values
string —getHeader()
Get the value of a specific response header.
    public
                getHeader(string $header) : string|null
        Requires the CURLOPT_HEADER option.
Parameters
- $header : string
 - 
                    
Name of the header (case-insensitive)
 
Return values
string|null —getHeaders()
Get all response headers.
    public
                getHeaders() : array<string|int, mixed>
        Requires the CURLOPT_HEADER option.
Tags
Return values
array<string|int, mixed> —getInfo()
Get information about the response.
    public
                getInfo([int $option = null ]) : mixed
    
        Parameters
- $option : int = null
 - 
                    
(optional)CURLINFO_* value (Returns an array with all info if no $option is given)
 
Return values
mixed —hasEvent()
Check id the $event is a registered event.
    public
                hasEvent(string $event) : bool
    
        Parameters
- $event : string
 
Return values
bool —isComplete()
Check if this request is complete.
    public
                isComplete() : bool
    
    
    
    Tags
Return values
bool —off()
Remove a callback from an event.
    public
                off(string $event, string $identifier) : mixed
    
        Parameters
- $event : string
 - $identifier : string
 
Return values
mixed —on()
Add a callback for an event.
    public
                on(string $event, Closure|string|array<string|int, mixed> $callback) : string
    
        Parameters
- $event : string
 - $callback : Closure|string|array<string|int, mixed>
 
Return values
string —identifier
post()
Preform an asynchonous POST request.
    public
            static    post(string $url[, array<string|int, mixed>|string $data = [] ][, array<string|int, mixed> $options = [] ][, Closure|callable $callback = null ]) : Curl
    
        Parameters
- $url : string
 - $data : array<string|int, mixed>|string = []
 - $options : array<string|int, mixed> = []
 - 
                    
Additional CURLOPT_* options
 - $callback : Closure|callable = null
 - 
                    
The callback for the load event.
 
Return values
Curl —Response
proxy()
Proxy/resend the current request to different url/server.
    public
            static    proxy(string $endpoint[, callable $filter = null ]) : mixed
    
        Parameters
- $endpoint : string
 - 
                    
Url
 - $filter : callable = null
 - 
                    
Callback to change the generated Curl options.
 
Return values
mixed —put()
Preform an asynchonous PUT request.
    public
            static    put(string $url[, string|array<string|int, mixed> $data = '' ][, array<string|int, mixed> $options = [] ][, Closure|callable $callback = null ]) : Curl
    
        Parameters
- $url : string
 - $data : string|array<string|int, mixed> = ''
 - $options : array<string|int, mixed> = []
 - 
                    
Additional CURLOPT_* options
 - $callback : Closure|callable = null
 - 
                    
The callback for the load event.
 
Return values
Curl —Response
putFile()
Preform an asynchonous PUT request.
    public
            static    putFile(string $url, string $filename[, array<string|int, mixed> $options = [] ][, callable $callback = null ]) : Curl
        Override the CURLOPT_INFILESIZE when dealing with large files. filesize() has issues in PHP 32bit with files bigger than 2GiB.
Parameters
- $url : string
 - $filename : string
 - $options : array<string|int, mixed> = []
 - 
                    
Additional CURLOPT_* options
 - $callback : callable = null
 - 
                    
The callback for the load event.
 
Return values
Curl —resend()
Reuse the curl handle/connection to (re)send an request Use the options to override settings from the previous request.
    public
                resend([mixed $options = [] ]) : mixed
    
        Parameters
- $options : mixed = []
 
Return values
mixed —synchronize()
Wait for all requests to complete.
    public
            static    synchronize() : mixed
    
    
    
    Tags
Return values
mixed —trigger()
Trigger an event.
    public
                trigger(string $event, stdClass $sender[, mixed $args = null ]) : mixed
    
        Parameters
- $event : string
 - $sender : stdClass
 - $args : mixed = null
 - 
                    
(optional)
 
Return values
mixed —waitForCompletion()
Wait for the request to complete.
    public
                waitForCompletion() : mixed
    
    
    
    Tags
Return values
mixed —defaults()
Merge options with the default options.
    private
            static    defaults([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
        Used in the static get, post, put, delete and download methods.
Parameters
- $options : array<string|int, mixed> = []
 - 
                    
Additional defaults
 
Return values
array<string|int, mixed> —errorName()
Convert a CURLE_* integer to the constantname.
    private
            static    errorName(int $number) : string
    
        Parameters
- $number : int
 
Return values
string —multiErrorName()
Convert a CURLM_* integer to the constantname.
    private
            static    multiErrorName(int $number) : string
    
        Parameters
- $number : int
 
Return values
string —optionName()
Convert a CURLOPT_* integer to the constantname.
    private
            static    optionName(int $number) : string
    
        Parameters
- $number : int
 
Return values
string —start()
Start the request 1. Set the CURLOPT_* options 2. Add the request to the pool 3. Starts the request.
    private
                start(array<string|int, mixed> $options) : mixed
    
        Parameters
- $options : array<string|int, mixed>
 - 
                    
CURLOPT_* options
 
Tags
Return values
mixed —stop()
Remove the request from the pool.
    private
                stop() : mixed
    
    
    
    Tags
Return values
mixed —throttle()
Limit the number of active transfers.
    private
            static    throttle(int $max) : mixed
    
        Parameters
- $max : int
 - 
                    
The allowed number of active connections.