1 | <?php |
||
5 | class Agent |
||
6 | { |
||
7 | protected $maxConcurrent = 0; //max. number of simultaneous connections allowed |
||
8 | protected $options = []; //shared cURL options |
||
9 | protected $headers = []; //shared cURL request headers |
||
10 | protected $timeout = 5000; //timeout used for curl_multi_select function |
||
11 | protected $post = []; |
||
12 | protected $startTime; |
||
13 | protected $endTime; |
||
14 | |||
15 | // TODO: normalize headers key => value is key: value |
||
16 | |||
17 | /** |
||
18 | * @var RequestInterface[] $requests array of Requests |
||
19 | */ |
||
20 | protected $requests; |
||
21 | |||
22 | /** |
||
23 | * @var callable[] $listeners array of listeners |
||
24 | */ |
||
25 | protected $listeners = []; |
||
26 | protected $mh; |
||
27 | |||
28 | /** |
||
29 | * Agent constructor. |
||
30 | * @param int $max_concurrent max current requests |
||
31 | */ |
||
32 | function __construct($max_concurrent = 10) |
||
36 | |||
37 | /** |
||
38 | * Set the maximum number of concurrent requests |
||
39 | * @param int $max_requests maximum concurrent requests |
||
40 | */ |
||
41 | public function setMaxConcurrent($max_requests) |
||
47 | |||
48 | /** |
||
49 | * Set global cUrl options |
||
50 | * @param array $options array of options |
||
51 | */ |
||
52 | public function setOptions(array $options) |
||
58 | |||
59 | /** |
||
60 | * Set global cUrl headers |
||
61 | * @param array $headers headers |
||
62 | */ |
||
63 | public function setHeaders(array $headers) |
||
69 | |||
70 | /** |
||
71 | * Set global timeout |
||
72 | * If individual requests don't have a timeout value, this will be used |
||
73 | * @param int $timeout timeout in msec |
||
74 | */ |
||
75 | public function setTimeout($timeout) |
||
81 | |||
82 | /** |
||
83 | * Adds a new request to the queue and returns it |
||
84 | * this request will have its default options set to global options |
||
85 | * @param null $url URL to send the request to |
||
86 | * @return RequestInterface the newly added request object |
||
87 | */ |
||
88 | public function newRequest($url = null) |
||
92 | |||
93 | /** |
||
94 | * Add a request to the request queue |
||
95 | * @param RequestInterface $request the request to add |
||
96 | * @return RequestInterface |
||
97 | */ |
||
98 | public function addRequest(RequestInterface $request, $setGlobals = false) |
||
109 | |||
110 | /** |
||
111 | * Returns the Request object for a give cUrl handle |
||
112 | * @param mixed $handle |
||
113 | * @return RequestInterface request with handle |
||
114 | */ |
||
115 | private function getRequestByHandle($handle) |
||
123 | |||
124 | /** |
||
125 | * Execute the request queue |
||
126 | */ |
||
127 | public function execute() |
||
158 | } |
||
159 | ?> |
||
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.