summaryrefslogtreecommitdiff
path: root/tests/metrics-issue-571.php
blob: 947ae1f7cdf3a7827326c96afe190812844d46b2 (plain)
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
<?php

use Spiral\Goridge;
use Spiral\RoadRunner;
use Nyholm\Psr7\Factory;

ini_set('display_errors', 'stderr');
require __DIR__ . "/vendor/autoload.php";

$worker = new RoadRunner\Http\PSR7Worker(
	RoadRunner\Worker::create(),
	new Factory\Psr17Factory(),
	new Factory\Psr17Factory(),
	new Factory\Psr17Factory()
);

$metrics = new RoadRunner\Metrics\Metrics(
	Goridge\RPC\RPC::create(RoadRunner\Environment::fromGlobals()->getRPCAddress())
);

$metrics->declare(
	'test',
	RoadRunner\Metrics\Collector::counter()->withHelp('Test counter')
);

while ($req = $worker->waitRequest()) {
	try {
		$rsp = new \Nyholm\Psr7\Response();
		$rsp->getBody()->write("hello world");

		$metrics->add('test', 1);

		$worker->respond($rsp);
	} catch (\Throwable $e) {
		$worker->getWorker()->error((string)$e);
	}
}