PHP Class RollingCurl\RollingCurl

Afficher le fichier Open project: chuyskywalker/rolling-curl Class Usage Examples

Protected Properties

Свойство Type Description
$multicurlOptions array Set your default multicurl options
$options array Set your base options that you want to be used with EVERY request. (Can be overridden individually)

Méthodes publiques

Méthode Description
add ( RollingCurl\Request $request ) : RollingCurl Add a request to the request queue
addMulticurlOptions ( array $multicurlOptions ) : RollingCurl Override and add multicurlOptions
addOptions ( array $options ) : RollingCurl Override and add options
clearCompleted ( ) : RollingCurl Clear out all completed requests
countActive ( ) : integer
countCompleted ( boolean $useArray = false ) : integer
countPending ( ) : integer
delete ( string $url, array $headers = null, array $options = null ) : RollingCurl Perform DELETE request
execute ( ) : void Run all queued requests
get ( string $url, array $headers = null, array $options = null ) : RollingCurl Perform GET request
getCallback ( ) : callable
getCompletedRequests ( ) : RollingCurl\Request[]
getHeaders ( ) : array
getIdleCallback ( ) : callable
getMulticurlOptions ( ) : array
getOptions ( ) : array
getSimultaneousLimit ( ) : integer
post ( string $url, array | string $postData = null, array $headers = null, array $options = null ) : RollingCurl Perform POST request
prunePendingRequestQueue ( ) : RollingCurl Removes requests from the queue that have already been processed
put ( string $url, null $putData = null, array $headers = null, array $options = null ) : RollingCurl Perform PUT request
request ( string $url, string $method = "GET", array | string $postData = null, array $headers = null, array $options = null ) : RollingCurl Create new Request and add it to the request queue
setCallback ( callable $callback ) : RollingCurl Define a callable to handle the response.
setHeaders ( array $headers ) : RollingCurl
setIdleCallback ( callable $callback ) : RollingCurl Define a callable to be called when waiting for responses.
setMulticurlOptions ( array $multicurlOptions ) : RollingCurl
setOptions ( array $options ) : RollingCurl
setSimultaneousLimit ( integer $count ) : RollingCurl Set the limit for how many cURL requests will be execute simultaneously.

Private Methods

Méthode Description
getNextPendingRequest ( ) : null | RollingCurl\Request Get the next pending request, or return null
getNextPendingRequests ( integer $limit = 1 ) : RollingCurl\Request[] Return the next $limit pending requests (may return an empty array)
prepareRequestOptions ( RollingCurl\Request $request ) : array Helper function to gather all the curl options: global, inferred, and per request

Method Details

add() public méthode

Add a request to the request queue
public add ( RollingCurl\Request $request ) : RollingCurl
$request RollingCurl\Request
Résultat RollingCurl

addMulticurlOptions() public méthode

Override and add multicurlOptions
public addMulticurlOptions ( array $multicurlOptions ) : RollingCurl
$multicurlOptions array
Résultat RollingCurl

addOptions() public méthode

Override and add options
public addOptions ( array $options ) : RollingCurl
$options array
Résultat RollingCurl

clearCompleted() public méthode

If you are running a very large number of requests, it's a good idea to call this every few completed requests so you don't run out of memory.
public clearCompleted ( ) : RollingCurl
Résultat RollingCurl

countActive() public méthode

public countActive ( ) : integer
Résultat integer

countCompleted() public méthode

public countCompleted ( boolean $useArray = false ) : integer
$useArray boolean count the completedRequests array is true. Otherwise use the global counter.
Résultat integer

countPending() public méthode

public countPending ( ) : integer
Résultat integer

delete() public méthode

Perform DELETE request
public delete ( string $url, array $headers = null, array $options = null ) : RollingCurl
$url string
$headers array
$options array
Résultat RollingCurl

execute() public méthode

Run all queued requests
public execute ( ) : void
Résultat void

get() public méthode

Perform GET request
public get ( string $url, array $headers = null, array $options = null ) : RollingCurl
$url string
$headers array
$options array
Résultat RollingCurl

getCallback() public méthode

public getCallback ( ) : callable
Résultat callable

getCompletedRequests() public méthode

public getCompletedRequests ( ) : RollingCurl\Request[]
Résultat RollingCurl\Request[]

getHeaders() public méthode

public getHeaders ( ) : array
Résultat array

getIdleCallback() public méthode

public getIdleCallback ( ) : callable
Résultat callable

getMulticurlOptions() public méthode

public getMulticurlOptions ( ) : array
Résultat array

getOptions() public méthode

public getOptions ( ) : array
Résultat array

getSimultaneousLimit() public méthode

public getSimultaneousLimit ( ) : integer
Résultat integer

post() public méthode

Perform POST request
public post ( string $url, array | string $postData = null, array $headers = null, array $options = null ) : RollingCurl
$url string
$postData array | string
$headers array
$options array
Résultat RollingCurl

prunePendingRequestQueue() public méthode

Beceause the request queue does not shrink during processing (merely traversed), it is sometimes necessary to prune the queue. This method creates a new array starting at the first un-processed request, replaces the old queue and resets counters.
public prunePendingRequestQueue ( ) : RollingCurl
Résultat RollingCurl

put() public méthode

Perform PUT request
public put ( string $url, null $putData = null, array $headers = null, array $options = null ) : RollingCurl
$url string
$putData null
$headers array
$options array
Résultat RollingCurl

request() public méthode

Create new Request and add it to the request queue
public request ( string $url, string $method = "GET", array | string $postData = null, array $headers = null, array $options = null ) : RollingCurl
$url string
$method string
$postData array | string
$headers array
$options array
Résultat RollingCurl

setCallback() public méthode

It can be an anonymous function: $rc = new RollingCurl(); $rc->setCallback(function($request, $rolling_curl) { process }); Or an existing function: class MyClass { function doCurl() { $rc = new RollingCurl(); $rc->setCallback(array($this, 'callback')); } Cannot be private or protected public function callback($request, $rolling_curl) { process } } The called code should expect two parameters: \RollingCurl\Request $request, \RollingCurl\RollingCurl $rollingCurl $request is original request object, but now with body, headers, response code, etc $rollingCurl is the rolling curl object itself (useful if you want to re/queue a URL)
public setCallback ( callable $callback ) : RollingCurl
$callback callable
Résultat RollingCurl

setHeaders() public méthode

public setHeaders ( array $headers ) : RollingCurl
$headers array
Résultat RollingCurl

setIdleCallback() public méthode

Define a callable to be called when waiting for responses.
public setIdleCallback ( callable $callback ) : RollingCurl
$callback callable
Résultat RollingCurl

setMulticurlOptions() public méthode

public setMulticurlOptions ( array $multicurlOptions ) : RollingCurl
$multicurlOptions array
Résultat RollingCurl

setOptions() public méthode

public setOptions ( array $options ) : RollingCurl
$options array
Résultat RollingCurl

setSimultaneousLimit() public méthode

Please be mindful that if you set this too high, requests are likely to fail more frequently or automated software may perceive you as a DOS attack and automatically block further requests.
public setSimultaneousLimit ( integer $count ) : RollingCurl
$count integer
Résultat RollingCurl

Property Details

$multicurlOptions protected_oe property

Set your default multicurl options
protected array $multicurlOptions
Résultat array

$options protected_oe property

Set your base options that you want to be used with EVERY request. (Can be overridden individually)
protected array $options
Résultat array