ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 64 of file CurlMultiRequest.php.

65  {
66  if ($this->_sent) {
68  'Request has already been sent cannot '.__METHOD__
69  );
70  }
71  if (!$request instanceof CAS_Request_CurlRequest) {
73  'As a CAS_Request_CurlMultiRequest, I can only work with CAS_Request_CurlRequest objects.'
74  );
75  }
76 
77  $this->_requests[] = $request;
78  }
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 85 of file CurlMultiRequest.php.

86  {
87  if ($this->_sent) {
89  'Request has already been sent cannot '.__METHOD__
90  );
91  }
92  return count($this->_requests);
93  }
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 106 of file CurlMultiRequest.php.

References $i, and array.

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

Field Documentation

◆ $_requests

CAS_Request_CurlMultiRequest::$_requests = array()
private

Definition at line 45 of file CurlMultiRequest.php.

◆ $_sent

CAS_Request_CurlMultiRequest::$_sent = false
private

Definition at line 46 of file CurlMultiRequest.php.


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