-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathReporter.php
More file actions
48 lines (43 loc) · 1.46 KB
/
Copy pathReporter.php
File metadata and controls
48 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer\Support;
use Symfony\Component\Process\PhpProcess;
/**
* @codeCoverageIgnore
*/
class Reporter
{
public static function report(array $stats): void
{
$version = DEPLOYER_VERSION;
$body = json_encode($stats);
$length = strlen($body);
$php = new PhpProcess(<<<EOF
<?php
\$ch = curl_init('https://deployer.org/api/stats');
curl_setopt(\$ch, CURLOPT_USERAGENT, 'Deployer/$version');
curl_setopt(\$ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt(\$ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: $length',
]);
curl_setopt(\$ch, CURLOPT_POSTFIELDS, '$body');
curl_setopt(\$ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt(\$ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(\$ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt(\$ch, CURLOPT_MAXREDIRS, 10);
curl_setopt(\$ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt(\$ch, CURLOPT_TIMEOUT, 5);
\$result = curl_exec(\$ch);
if (PHP_MAJOR_VERSION < 8) {
curl_close(\$ch);
}
EOF);
$php->start();
}
}