Completed
Push — master ( 8cc4ca...2aa5db )
by Taosikai
11:59
created

Utils   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 53
c 0
b 0
f 0
rs 10
1
<?php
2
namespace Slince\Process\Tests;
3
4
final class Utils
5
{
6
    protected static $pd;
7
8
    /**
9
     * Creates a native read-only fifo fd
10
     * @param $pathname
11
     * @return bool|resource
12
     */
13
    public static function makeNativeReadFifo($pathname)
14
    {
15
        if (!file_exists($pathname)) {
16
            posix_mkfifo($pathname, 0666);
17
        }
18
        $fifo = fopen($pathname, 'r+');
19
        return $fifo;
20
    }
21
22
    /**
23
     * Creates a native write-only fifo fd
24
     * @param string $pathname
25
     * @return bool|resource
26
     */
27
    public static function makeNativeWriteFifo($pathname)
28
    {
29
        if (!file_exists($pathname)) {
30
            posix_mkfifo($pathname, 0666);
31
        }
32
        $fifo = fopen($pathname, 'r+');
33
        return $fifo;
34
    }
35
36
    /**
37
     * Executes the command
38
     * @param string $command
39
     * @return bool|resource
40
     */
41
    public static function asyncExecute($command)
42
    {
43
        $pd = popen($command, 'r');
44
        stream_set_blocking($pd, false);
45
        return $pd;
46
    }
47
48
    /**
49
     * Gets last pipe id
50
     * @return resource
51
     */
52
    public static function getLastPd()
53
    {
54
        return static::$pd;
55
    }
56
}
57