1 | <?php |
||
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 |