1 | <?php |
||
21 | class Agent |
||
22 | { |
||
23 | /** |
||
24 | * @var array results |
||
25 | */ |
||
26 | protected $result; |
||
27 | |||
28 | /** |
||
29 | * @var array responses |
||
30 | */ |
||
31 | protected $response; |
||
32 | |||
33 | /** |
||
34 | * @var int The maximum number of simultaneous connections allowed |
||
35 | */ |
||
36 | protected $maxConcurrent = 0; |
||
37 | |||
38 | /** |
||
39 | * @var RequestInterface[] array of Requests |
||
40 | */ |
||
41 | protected $requests; |
||
42 | |||
43 | /** |
||
44 | * @var Request default request |
||
45 | */ |
||
46 | protected $defaultRequest; |
||
47 | |||
48 | /** |
||
49 | * @var resource cUrl Multi Handle |
||
50 | */ |
||
51 | protected $mh; |
||
52 | |||
53 | protected $requestCounter = 0; |
||
54 | |||
55 | /** |
||
56 | * Agent constructor. |
||
57 | * @param int $max_concurrent max current requests |
||
58 | */ |
||
59 | function __construct($max_concurrent = 10) |
||
64 | |||
65 | function __destruct() |
||
72 | |||
73 | /** |
||
74 | * Magic setter function |
||
75 | * @param string $name attribute to set |
||
76 | * @param mixed $value the new value |
||
77 | * @return void |
||
78 | */ |
||
79 | public function __set($name, $value) |
||
89 | |||
90 | /** |
||
91 | * Magic getter function |
||
92 | * @param string $name of the attribute to get |
||
93 | * @return mixed the attribute's value |
||
94 | */ |
||
95 | public function __get($name) |
||
105 | |||
106 | /** |
||
107 | * Set the maximum number of concurrent requests |
||
108 | * @param int $max_requests maximum concurrent requests |
||
109 | */ |
||
110 | public function setMaxConcurrent($max_requests) |
||
116 | |||
117 | /** |
||
118 | * Get the currently set value of maxConcurrent |
||
119 | * @return int maximum number of concurrent requests |
||
120 | */ |
||
121 | public function getMaxConcurrent() |
||
125 | |||
126 | /** |
||
127 | * Adds a new request to the queue and returns it |
||
128 | * this request will have its default options set to global options |
||
129 | * @param null $url URL to send the request to |
||
130 | * @return RequestInterface the newly added request object |
||
131 | */ |
||
132 | public function newRequest($url = null) |
||
138 | |||
139 | /** |
||
140 | * Add a request to the request queue |
||
141 | * @param RequestInterface $request the request to add |
||
142 | * @return RequestInterface |
||
143 | */ |
||
144 | public function addRequest(RequestInterface $request) |
||
149 | |||
150 | /** |
||
151 | * Returns the Request object for a give cUrl handle |
||
152 | * @param resource $handle cUrl handle |
||
153 | * @return RequestInterface Request with handle |
||
154 | */ |
||
155 | protected function getRequestByHandle($handle) |
||
163 | |||
164 | /** |
||
165 | * Execute the request queue |
||
166 | */ |
||
167 | public function execute() |
||
203 | } |
||
204 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.