Completed
Pull Request — master (#12)
by Harry
07:37
created

SendBench::benchNewConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of graze/dog-statsd
4
 *
5
 * Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/dog-statsd/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/dog-statsd
12
 */
13
14
namespace Graze\DogStatsD\Test\Benchmark;
15
16
use Graze\DogStatsD\Client;
17
use Graze\DogStatsD\Test\TestCase;
18
19
class SendBench
20
{
21
    /**
22
     * @var resource|null
23
     */
24
    private $socket = null;
25
26
    /**
27
     * @Iterations(100)
28
     * @Revs(50)
29
     */
30
    public function benchPersistentConnection()
31
    {
32
        $message = "some stuff in here";
33
        if (is_null($this->socket)) {
34
            $this->socket = @fsockopen('udp://127.0.0.1', 8125, $errno, $errstr);
35
        }
36
        @fwrite($this->socket, $message);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
37
    }
38
39
    /**
40
     * @Iterations(100)
41
     * @Revs(50)
42
     */
43
    public function benchNewConnection()
44
    {
45
        $message = "some stuff in here";
46
        $socket = @fsockopen('udp://127.0.0.1', 8125, $errno, $errstr);
47
        fwrite($socket, $message);
48
        fclose($socket);
49
    }
50
}
51