Client
class Client implements SplSubject, Countable (View source)
The HTTP client. See http\Client\Curl's options which is the only driver currently supported.
Constants
DEBUG_INFO |
Debug callback's $data contains human readable text. |
DEBUG_IN |
Debug callback's $data contains data received. |
DEBUG_OUT |
Debug callback's $data contains data sent. |
DEBUG_HEADER |
Debug callback's $data contains headers. |
DEBUG_BODY |
Debug callback's $data contains a body part. |
DEBUG_SSL |
Debug callback's $data contains SSL data. |
Properties
protected array | $options | Set options. |
|
protected Message | $history | Request/response history. |
|
bool | $recordHistory | Whether to record history in http\Client::$history. |
Methods
Create a new HTTP client.
Add custom cookies.
Add specific SSL options.
Implements Countable. Retrieve the number of enqueued requests.
Implements SplSubject. Detach $observer, which has been previously attached.
Enable usage of an event library like libevent, which might improve performance with big socket sets.
Enable sending pipelined requests to the same host if the driver supports it.
Get a list of available configuration options and their default values.
List available drivers.
Retrieve a list of available request options and their default values.
Get priorly set custom cookies.
Simply returns the http\Message chain representing the request/response history.
Returns the SplObjectStorage holding attached observers.
Get priorly set options.
Retrieve the corresponding response of an already finished request, or the last received response if $request is not set.
Retrieve priorly set SSL options.
Get transfer related information for a running or finished request.
Perform outstanding transfer actions.
Set custom cookies.
Set client options.
Specifically set SSL options.
Wait for $timeout seconds for transfers to provide data.
Details
__construct(string $driver = null, string $persistent_handle_id = null)
Create a new HTTP client.
Currently only "curl" is supported as a $driver, and used by default. Persisted resources identified by $persistent_handle_id will be re-used if available.
Client
addCookies(array $cookies = null)
Add custom cookies.
See http\Client::setCookies().
Client
addSslOptions(array $ssl_options = null)
Add specific SSL options.
See http\Client::setSslOptions(), http\Client::setOptions() and http\Client\Curl\$ssl options.
void
attach(SplObserver $observer)
Implements SplSubject. Attach another observer.
Attached observers will be notified with progress of each transfer.
Client
configure(array $configuration)
Configure the client's low level options.
NOTE: This method has been added in v2.3.0.
int
count()
Implements Countable. Retrieve the number of enqueued requests.
NOTE: The enqueued requests are counted without regard whether they are finished or not.
Client
dequeue(Request $request)
Dequeue the http\Client\Request $request.
See http\Client::requeue(), if you want to requeue the request, instead of calling http\Client::dequeue() and then http\Client::enqueue().
void
detach(SplObserver $observer)
Implements SplSubject. Detach $observer, which has been previously attached.
Client
enableEvents(bool $enable = true)
Enable usage of an event library like libevent, which might improve performance with big socket sets.
Client
enablePipelining(bool $enable = true)
Enable sending pipelined requests to the same host if the driver supports it.
Client
enqueue(Request $request, callable $cb = null)
Add another http\Client\Request to the request queue.
If the optional callback $cb returns true, the request will be automatically dequeued.
Note: The http\Client\Response object resulting from the request is always stored internally to be retrieved at a later time, even when $cb is used.
If you are about to send a lot of requests and do not need the response after executing the callback, you can use http\Client::getResponse() within the callback to keep the memory usage level as low as possible.
See http\Client::dequeue() and http\Client::send().
array
getAvailableConfiguration()
Get a list of available configuration options and their default values.
See f.e. the configuration options for the Curl driver.
array
getAvailableDrivers()
List available drivers.
array
getAvailableOptions()
Retrieve a list of available request options and their default values.
See f.e. the request options for the Curl driver.
array
getCookies()
Get priorly set custom cookies.
See http\Client::setCookies().
Message
getHistory()
Simply returns the http\Message chain representing the request/response history.
NOTE: The history is only recorded while http\Client::$recordHistory is true.
SplObjectStorage
getObservers()
Returns the SplObjectStorage holding attached observers.
array
getOptions()
Get priorly set options.
See http\Client::setOptions().
object|null
getProgressInfo(Request $request)
Retrieve the progress information for $request.
Response|null
getResponse(Request $request = null)
Retrieve the corresponding response of an already finished request, or the last received response if $request is not set.
NOTE: If $request is NULL, then the response is removed from the internal storage (stack-like operation).
array
getSslOptions()
Retrieve priorly set SSL options.
See http\Client::getOptions() and http\Client::setSslOptions().
object
getTransferInfo(Request $request)
Get transfer related information for a running or finished request.
void
notify(Request $request = null, object $progress = null)
Implements SplSubject. Notify attached observers about progress with $request.
bool
once()
Perform outstanding transfer actions.
See http\Client::wait() for the completing interface.
Client
requeue(Request $request, callable $cb = null)
Requeue an http\Client\Request.
The difference simply is, that this method, in contrast to http\Client::enqueue(), does not throw an http\Exception when the request to queue is already enqueued and dequeues it automatically prior enqueueing it again.
Client
reset()
Reset the client to the initial state.
Client
send()
Send all enqueued requests.
See http\Client::once() and http\Client::wait() for a more fine grained interface.
Client
setCookies(array $cookies = null)
Set custom cookies.
See http\Client::addCookies() and http\Client::getCookies().
Client
setDebug(callable $callback)
Set client debugging callback.
NOTE: This method has been added in v2.6.0, resp. v3.1.0.
Client
setOptions(array $options = null)
Set client options.
See http\Client\Curl.
NOTE: Only options specified prior enqueueing a request are applied to the request.
Client
setSslOptions(array $ssl_options = null)
Specifically set SSL options.
See http\Client::setOptions() and http\Client\Curl\$ssl options.
bool
wait(float $timeout = 0)
Wait for $timeout seconds for transfers to provide data.
This is the completion call to http\Client::once().