ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CAS_Request_CurlMultiRequest Class Reference

This interface defines a class library for performing multiple web requests in batches. More...

+ Inheritance diagram for CAS_Request_CurlMultiRequest:
+ Collaboration diagram for CAS_Request_CurlMultiRequest:

Public Member Functions

 addRequest (CAS_Request_RequestInterface $request)
 Add a new Request to this batch. More...
 
 getNumRequests ()
 Retrieve the number of requests added to this batch. More...
 
 send ()
 Perform the request. More...
 
- Public Member Functions inherited from CAS_Request_MultiRequestInterface
 addRequest (CAS_Request_RequestInterface $request)
 Add a new Request to this batch. More...
 
 getNumRequests ()
 Retrieve the number of requests added to this batch. More...
 
 send ()
 Perform the request. More...
 

Private Attributes

 $_requests = array()
 
 $_sent = false
 

Detailed Description

This interface defines a class library for performing multiple web requests in batches.

Implementations of this interface may perform requests serially or in parallel.

Definition at line 42 of file CurlMultiRequest.php.

Member Function Documentation

◆ addRequest()

CAS_Request_CurlMultiRequest::addRequest ( CAS_Request_RequestInterface  $request)

Add a new Request to this batch.

Note, implementations will likely restrict requests to their own concrete class hierarchy.

Parameters
CAS_Request_RequestInterface$requestreqest to add
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.
CAS_InvalidArgumentExceptionIf passed a Request of the wrong implmentation.

Definition at line 63 of file CurlMultiRequest.php.

References $request.

64  {
65  if ($this->_sent) {
67  'Request has already been sent cannot ' . __METHOD__
68  );
69  }
70  if (!$request instanceof CAS_Request_CurlRequest) {
72  'As a CAS_Request_CurlMultiRequest, I can only work with CAS_Request_CurlRequest objects.'
73  );
74  }
75 
76  $this->_requests[] = $request;
77  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
Provides support for performing web-requests via curl.
Definition: CurlRequest.php:40
This class defines Exceptions that should be thrown when the sequence of operations is invalid...
Exception that denotes invalid arguments were passed.

◆ getNumRequests()

CAS_Request_CurlMultiRequest::getNumRequests ( )

Retrieve the number of requests added to this batch.

Returns
number of request elements

Definition at line 84 of file CurlMultiRequest.php.

85  {
86  if ($this->_sent) {
88  'Request has already been sent cannot ' . __METHOD__
89  );
90  }
91  return count($this->_requests);
92  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ send()

CAS_Request_CurlMultiRequest::send ( )

Perform the request.

After sending, all requests will have their responses poulated.

Returns
bool TRUE on success, FALSE on failure.
Exceptions
CAS_OutOfSequenceExceptionIf called multiple times.

Definition at line 105 of file CurlMultiRequest.php.

References $i, and $request.

106  {
107  if ($this->_sent) {
108  throw new CAS_OutOfSequenceException(
109  'Request has already been sent cannot send again.'
110  );
111  }
112  if (!count($this->_requests)) {
113  throw new CAS_OutOfSequenceException(
114  'At least one request must be added via addRequest() before the multi-request can be sent.'
115  );
116  }
117 
118  $this->_sent = true;
119 
120  // Initialize our handles and configure all requests.
121  $handles = array();
122  $multiHandle = curl_multi_init();
123  foreach ($this->_requests as $i => $request) {
124  $handle = $request->initAndConfigure();
125  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
126  $handles[$i] = $handle;
127  curl_multi_add_handle($multiHandle, $handle);
128  }
129 
130  // Execute the requests in parallel.
131  do {
132  curl_multi_exec($multiHandle, $running);
133  } while ($running > 0);
134 
135  // Populate all of the responses or errors back into the request objects.
136  foreach ($this->_requests as $i => $request) {
137  $buf = curl_multi_getcontent($handles[$i]);
138  $request->_storeResponseBody($buf);
139  curl_multi_remove_handle($multiHandle, $handles[$i]);
140  curl_close($handles[$i]);
141  }
142 
143  curl_multi_close($multiHandle);
144  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
This class defines Exceptions that should be thrown when the sequence of operations is invalid...
$i
Definition: disco.tpl.php:19

Field Documentation

◆ $_requests

CAS_Request_CurlMultiRequest::$_requests = array()
private

Definition at line 44 of file CurlMultiRequest.php.

◆ $_sent

CAS_Request_CurlMultiRequest::$_sent = false
private

Definition at line 45 of file CurlMultiRequest.php.


The documentation for this class was generated from the following file: