1 | <?php |
||
19 | class Thread implements ThreadInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var ThreadInterface |
||
23 | */ |
||
24 | private $threadInstance = null; |
||
25 | |||
26 | /** |
||
27 | * constructor method |
||
28 | * |
||
29 | * @param mixed $callable string with the function name or a array with the instance and the method name |
||
30 | * @throws RuntimeException |
||
31 | * @throws InvalidArgumentException |
||
32 | */ |
||
33 | public function __construct(callable $callable) |
||
37 | |||
38 | private $threadHandlerArguments = []; |
||
39 | |||
40 | /** |
||
41 | * @param array $arguments |
||
42 | */ |
||
43 | public function setThreadHandlerArguments($arguments) |
||
47 | |||
48 | private function getThreadHandlerArguments($property) |
||
52 | |||
53 | /** |
||
54 | * @return ThreadInterface |
||
55 | */ |
||
56 | public function getThreadInstance() |
||
78 | |||
79 | |||
80 | /** |
||
81 | * Start the thread |
||
82 | * |
||
83 | * @throws RuntimeException |
||
84 | */ |
||
85 | public function execute() |
||
90 | |||
91 | /** |
||
92 | * Get the thread result from the shared memory block and erase it |
||
93 | * |
||
94 | * @return mixed |
||
95 | */ |
||
96 | public function getResult() |
||
100 | |||
101 | /** |
||
102 | * Kill a thread |
||
103 | * |
||
104 | * @param int $signal |
||
105 | * @param bool $wait |
||
106 | */ |
||
107 | public function stop($signal = SIGKILL, $wait = false) |
||
111 | |||
112 | /** |
||
113 | * Check if the forked process is alive |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function isAlive() |
||
120 | |||
121 | public function waitFinish() |
||
125 | |||
126 | /** |
||
127 | * Set the thread callable method |
||
128 | * @param callable $callable |
||
129 | * @return mixed |
||
130 | */ |
||
131 | public function setCallable(callable $callable) |
||
135 | } |
||
136 |