PluginProbe
Plausible Analytics / trunk
Plausible Analytics vtrunk
2.6.1 2.6.0 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 All 52 releases
plausible-analytics / src / Client / lib / Lib / GuzzleHttp / Handler / CurlHandler.php

CurlHandler.php in Plausible Analytics trunk, at src/Client/lib/Lib/GuzzleHttp/Handler/CurlHandler.php

50 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Plausible\Analytics\WP\Client\Lib\GuzzleHttp\Handler;
4
5 use Plausible\Analytics\WP\Client\Lib\GuzzleHttp\Promise\PromiseInterface;
6 use Plausible\Analytics\WP\Client\Lib\Psr\Http\Message\RequestInterface;
7
8 /**
9 * HTTP handler that uses cURL easy handles as a transport layer.
10 *
11 * When using the CurlHandler, custom curl options can be specified as an
12 * associative array of curl option constants mapping to values in the
13 * **curl** key of the "client" key of the request.
14 *
15 * @final
16 */
17 class CurlHandler
18 {
19 /**
20 * @var CurlFactoryInterface
21 */
22 private $factory;
23
24 /**
25 * Accepts an associative array of options:
26 *
27 * - handle_factory: Optional curl factory used to create cURL handles.
28 *
29 * @param array{handle_factory?: ?CurlFactoryInterface} $options Array of options to use with the handler
30 */
31 public function __construct(array $options = [])
32 {
33 $this->factory = $options['handle_factory']
34 ?? new CurlFactory(3);
35 }
36
37 public function __invoke(RequestInterface $request, array $options): PromiseInterface
38 {
39 if (isset($options['delay'])) {
40 \usleep($options['delay'] * 1000);
41 }
42
43 $easy = $this->factory->create($request, $options);
44 \curl_exec($easy->handle);
45 $easy->errno = \curl_errno($easy->handle);
46
47 return CurlFactory::finish($this, $easy, $this->factory);
48 }
49 }
50