CurlMulti
extends AbstractHasDispatcher
in package
implements
CurlMultiInterface
Send {@see RequestInterface} objects in parallel using curl_multi
Table of Contents
Interfaces
- CurlMultiInterface
- Interface for sending a pool of {@see RequestInterface} objects in parallel
Properties
- $eventDispatcher : EventDispatcherInterface
- $exceptions : array<string|int, mixed>
- $handles : SplObjectStorage
- $multiErrors : array<string|int, mixed>
- $multiHandle : resource
- $requests : array<string|int, mixed>
- $resourceHash : array<string|int, mixed>
- $selectTimeout : float
- $successful : array<string|int, mixed>
Methods
- __construct() : mixed
- __destruct() : mixed
- add() : CurlMultiInterface
- Add a request to the pool.
- addSubscriber() : self
- Add an event subscriber to the dispatcher
- all() : array<string|int, mixed>
- Get an array of attached {@see RequestInterface} objects
- count() : mixed
- dispatch() : Event
- Helper to dispatch Guzzle events and set the event name on the event
- getAllEvents() : array<string|int, mixed>
- Get a list of all of the events emitted from the class
- getEventDispatcher() : EventDispatcherInterface
- Get the EventDispatcher of the request
- remove() : bool
- Remove a request from the pool.
- reset() : mixed
- Reset the state and remove any attached RequestInterface objects
- send() : mixed
- Send a pool of {@see RequestInterface} requests.
- setEventDispatcher() : self
- Set the EventDispatcher of the request
- beforeSend() : mixed
- Prepare for sending
- createCurlHandle() : CurlHandle
- Create a curl handle for a request
- perform() : mixed
- Get the data from the multi handle
- processResponse() : mixed
- Check for errors and fix headers of a request based on a curl response
- removeErroredRequest() : mixed
- Remove a request that encountered an exception
- removeHandle() : mixed
- Remove a curl handle from the curl multi object
- throwMultiException() : mixed
- Build and throw a MultiTransferException
- addHandle() : mixed
- checkCurlResult() : mixed
- Throw an exception for a cURL multi response if needed
- executeHandles() : mixed
- Execute and select curl handles
- isCurlException() : CurlException|bool
- Check if a cURL transfer resulted in what should be an exception
- processMessages() : mixed
- Process any received curl multi messages
- validateResponseWasSet() : mixed
Properties
$eventDispatcher
protected
EventDispatcherInterface
$eventDispatcher
$exceptions
protected
array<string|int, mixed>
$exceptions
= array()
Queued exceptions
$handles
protected
SplObjectStorage
$handles
RequestInterface to CurlHandle hash
$multiErrors
protected
array<string|int, mixed>
$multiErrors
= array(CURLM_BAD_HANDLE => array('CURLM_BAD_HANDLE', 'The passed-in handle is not a valid CURLM handle.'), CURLM_BAD_EASY_HANDLE => array('CURLM_BAD_EASY_HANDLE', "An easy handle was not good/valid. It could mean that it isn't an easy handle at all, or possibly that the handle already is in used by this or another multi handle."), CURLM_OUT_OF_MEMORY => array('CURLM_OUT_OF_MEMORY', 'You are doomed.'), CURLM_INTERNAL_ERROR => array('CURLM_INTERNAL_ERROR', 'This can only be returned if libcurl bugs. Please report it to us!'))
cURL multi error values and codes
$multiHandle
protected
resource
$multiHandle
cURL multi handle.
$requests
protected
array<string|int, mixed>
$requests
Attached RequestInterface objects.
$resourceHash
protected
array<string|int, mixed>
$resourceHash
Hash mapping curl handle resource IDs to request objects
$selectTimeout
protected
float
$selectTimeout
$successful
protected
array<string|int, mixed>
$successful
= array()
Requests that succeeded
Methods
__construct()
public
__construct([mixed $selectTimeout = 1.0 ]) : mixed
Parameters
- $selectTimeout : mixed = 1.0
__destruct()
public
__destruct() : mixed
add()
Add a request to the pool.
public
add(RequestInterface $request) : CurlMultiInterface
Parameters
- $request : RequestInterface
-
Request to add
Return values
CurlMultiInterfaceaddSubscriber()
Add an event subscriber to the dispatcher
public
addSubscriber(EventSubscriberInterface $subscriber) : self
Parameters
- $subscriber : EventSubscriberInterface
-
Event subscriber
Return values
selfall()
Get an array of attached {@see RequestInterface} objects
public
all() : array<string|int, mixed>
Return values
array<string|int, mixed>count()
public
count() : mixed
Attributes
- #[ReturnTypeWillChange]
dispatch()
Helper to dispatch Guzzle events and set the event name on the event
public
dispatch(mixed $eventName[, array<string|int, mixed> $context = array() ]) : Event
Parameters
- $eventName : mixed
-
Name of the event to dispatch
- $context : array<string|int, mixed> = array()
-
Context of the event
Return values
Event —Returns the created event object
getAllEvents()
Get a list of all of the events emitted from the class
public
static getAllEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>getEventDispatcher()
Get the EventDispatcher of the request
public
getEventDispatcher() : EventDispatcherInterface
Return values
EventDispatcherInterfaceremove()
Remove a request from the pool.
public
remove(RequestInterface $request) : bool
Parameters
- $request : RequestInterface
-
Request to remove
Return values
bool —Returns true on success or false on failure
reset()
Reset the state and remove any attached RequestInterface objects
public
reset([mixed $hard = false ]) : mixed
Parameters
- $hard : mixed = false
-
Set to true to close and reopen any open multi handles
send()
Send a pool of {@see RequestInterface} requests.
public
send() : mixed
setEventDispatcher()
Set the EventDispatcher of the request
public
setEventDispatcher(EventDispatcherInterface $eventDispatcher) : self
Parameters
- $eventDispatcher : EventDispatcherInterface
Return values
selfbeforeSend()
Prepare for sending
protected
beforeSend(RequestInterface $request) : mixed
Parameters
- $request : RequestInterface
-
Request to prepare
Tags
createCurlHandle()
Create a curl handle for a request
protected
createCurlHandle(RequestInterface $request) : CurlHandle
Parameters
- $request : RequestInterface
-
Request
Return values
CurlHandleperform()
Get the data from the multi handle
protected
perform() : mixed
processResponse()
Check for errors and fix headers of a request based on a curl response
protected
processResponse(RequestInterface $request, CurlHandle $handle, array<string|int, mixed> $curl) : mixed
Parameters
- $request : RequestInterface
-
Request to process
- $handle : CurlHandle
-
Curl handle object
- $curl : array<string|int, mixed>
-
Array returned from curl_multi_info_read
Tags
removeErroredRequest()
Remove a request that encountered an exception
protected
removeErroredRequest(RequestInterface $request[, Exception $e = null ]) : mixed
Parameters
- $request : RequestInterface
-
Request to remove
- $e : Exception = null
-
Exception encountered
removeHandle()
Remove a curl handle from the curl multi object
protected
removeHandle(RequestInterface $request) : mixed
Parameters
- $request : RequestInterface
-
Request that owns the handle
throwMultiException()
Build and throw a MultiTransferException
protected
throwMultiException(array<string|int, mixed> $exceptions, array<string|int, mixed> $successful) : mixed
Parameters
- $exceptions : array<string|int, mixed>
-
Exceptions encountered
- $successful : array<string|int, mixed>
-
Successful requests
Tags
addHandle()
private
addHandle(RequestInterface $request) : mixed
Parameters
- $request : RequestInterface
checkCurlResult()
Throw an exception for a cURL multi response if needed
private
checkCurlResult(int $code) : mixed
Parameters
- $code : int
-
Curl response code
Tags
executeHandles()
Execute and select curl handles
private
executeHandles() : mixed
isCurlException()
Check if a cURL transfer resulted in what should be an exception
private
isCurlException(RequestInterface $request, CurlHandle $handle, array<string|int, mixed> $curl) : CurlException|bool
Parameters
- $request : RequestInterface
-
Request to check
- $handle : CurlHandle
-
Curl handle object
- $curl : array<string|int, mixed>
-
Array returned from curl_multi_info_read
Return values
CurlException|boolprocessMessages()
Process any received curl multi messages
private
processMessages() : mixed
validateResponseWasSet()
private
validateResponseWasSet(RequestInterface $request) : mixed
Parameters
- $request : RequestInterface