forked from basicrum/beacon-sender
/
index.php
41 lines (31 loc) · 892 Bytes
/
index.php
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
<?php
require "vendor/autoload.php";
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\RequestException;
use Plugins\NavigationTimings\NavigationTimings;
use Plugins\Base\Base;
$shortopts = "u:";
$longopts = ["url:"];
$options = getopt($shortopts, $longopts);
if (!isset($options["u"]) && !isset($options["url"]))
{
die("You must provide catcher URL using -u or --url parameter".PHP_EOL);
}
$catcherUrl = $options["u"] ?? $options["url"];
$nt = new NavigationTimings();
$b = new Base();
$requestData = array_merge(
$nt->getMetrics(),
$b->getMetrics()
);
try {
$client = new Client();
$r = $client->post( $catcherUrl, ['form_params' => $requestData]);
$body = (string) $r->getBody();
} catch (RequestException $e) {
echo Psr7\str($e->getRequest());
if ($e->hasResponse()) {
echo Psr7\str($e->getResponse());
}
}