Pcntl::sigprocmask()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace PHP\Wrappers;
4
5
/**
6
 * Class Pcntl
7
 *
8
 * @package PHP\Wrappers
9
 * @author  Aurimas Niekis <[email protected]>
10
 */
11
class Pcntl
12
{
13
    /**
14
     * Set an alarm clock for delivery of a signal
15
     *
16
     * @param int $seconds The number of seconds to wait. If seconds is
17
     *                     zero, no new alarm is created.
18
     *
19
     * @return int
20
     */
21
    public function alarm(int $seconds) : int
22
    {
23
        return pcntl_alarm($seconds);
24
    }
25
26
    /**
27
     * Executes specified program in current process space
28
     *
29
     * @param string $path path must be the path to a binary executable or a
30
     *                     script with a valid path pointing to an executable in the shebang (
31
     *                     #!/usr/local/bin/perl for example) as the first line.  See your system's
32
     *                     man execve(2) page for additional information.
33
     * @param array  $args args is an array of argument strings passed to the
34
     *                     program.
35
     * @param array  $envs envs is an array of strings which are passed as
36
     *                     environment to the program.  The array is in the format of name => value,
37
     *                     the key being the name of the environmental variable and the value being
38
     *                     the value of that variable.
39
     *
40
     * @return bool
41
     */
42
    public function exec(string $path, array $args = null, array $envs = null) : bool
0 ignored issues
show
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $envs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        return call_user_func_array('pcntl_exec', func_get_args());
45
    }
46
47
    /**
48
     * Forks the currently running process
49
     *
50
     * @return int
51
     */
52
    public function fork() : int
53
    {
54
        return pcntl_fork();
55
    }
56
57
    /**
58
     * Retrieve the error number set by the last pcntl function which failed
59
     *
60
     * @return int
61
     */
62
    public function getLastError() : int
63
    {
64
        return pcntl_get_last_error();
65
    }
66
67
    /**
68
     * Get the priority of any process
69
     *
70
     * @param int $pid               If not specified, the pid of the current process is used.
71
     * @param int $processIdentifier One of PRIO_PGRP, PRIO_USER
72
     *                               or PRIO_PROCESS.
73
     *
74
     * @return int
75
     */
76
    public function getPriority(int $pid = null, int $processIdentifier = null) : int
0 ignored issues
show
Unused Code introduced by
The parameter $pid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $processIdentifier is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
    {
78
        return call_user_func_array('pcntl_getpriority', func_get_args());
79
    }
80
81
    /**
82
     * Change the priority of any process
83
     *
84
     * @param int $priority          priority is generally a value in the range
85
     *                               -20 to 20. The default priority
86
     *                               is 0 while a lower numerical value causes more
87
     *                               favorable scheduling.  Because priority levels can differ between
88
     *                               system types and kernel versions, please see your system's setpriority(2)
89
     *                               man page for specific details.
90
     * @param int $pid               If not specified, the pid of the current process is used.
91
     * @param int $processIdentifier One of PRIO_PGRP, PRIO_USER
92
     *                               or PRIO_PROCESS.
93
     *
94
     * @return bool
95
     */
96
    public function setPriority(int $priority, int $pid = null, int $processIdentifier = null) : bool
0 ignored issues
show
Unused Code introduced by
The parameter $priority is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $pid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $processIdentifier is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
    {
98
        return call_user_func_array('pcntl_setpriority', func_get_args());
99
    }
100
101
    /**
102
     * Calls signal handlers for pending signals
103
     *
104
     * @return bool
105
     */
106
    public function signalDispatch() : bool
107
    {
108
        return pcntl_signal_dispatch();
109
    }
110
111
    /**
112
     * Installs a signal handler
113
     *
114
     * @param int          $signo           The signal number.
115
     * @param callable|int $handler         The signal handler. This may be either a callable, which
116
     *                                      will be invoked to handle the signal, or either of the two global
117
     *                                      constants SIG_IGN or SIG_DFL,
118
     *                                      which will ignore the signal or restore the default signal handler
119
     *                                      respectively.
120
     * @param bool         $restartSyscalls Specifies whether system call restarting should be used when this
121
     *                                      signal arrives.
122
     *
123
     * @return bool
124
     */
125
    public function signal(int $signo, $handler, bool $restartSyscalls = null) : bool
0 ignored issues
show
Unused Code introduced by
The parameter $signo is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $handler is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $restartSyscalls is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
126
    {
127
        return call_user_func_array('pcntl_signal', func_get_args());
128
    }
129
130
    /**
131
     * Sets and retrieves blocked signals
132
     *
133
     * @param int   $how    Sets the behavior of pcntl_sigprocmask. Possible
134
     *                      values:
135
     *
136
     * SIG_BLOCK: Add the signals to the
137
     * currently blocked signals.
138
     * SIG_UNBLOCK: Remove the signals from the
139
     * currently blocked signals.
140
     * SIG_SETMASK: Replace the currently
141
     * blocked signals by the given list of signals.
142
     * @param array $set    List of signals.
143
     * @param array $oldset The oldset parameter is set to an array
144
     *                      containing the list of the previously blocked signals.
145
     *
146
     * @return bool
147
     */
148
    public function sigprocmask(int $how, array $set, array &$oldset = null) : bool
0 ignored issues
show
Unused Code introduced by
The parameter $how is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $set is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $oldset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
    {
150
        return call_user_func_array('pcntl_sigprocmask', func_get_args());
151
    }
152
153
    /**
154
     * Waits for signals, with a timeout
155
     *
156
     * @param array $set         Array of signals to wait for.
157
     * @param array $siginfo     The siginfo is set to an array containing
158
     *                           informations about the signal. See
159
     *                           pcntl_sigwaitinfo.
160
     * @param int   $seconds     Timeout in seconds.
161
     * @param int   $nanoseconds Timeout in nanoseconds.
162
     *
163
     * @return int
164
     */
165
    public function sigtimedwait(array $set, array &$siginfo = null, int $seconds = null, int $nanoseconds = null) : int
0 ignored issues
show
Unused Code introduced by
The parameter $set is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $siginfo is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $seconds is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $nanoseconds is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
166
    {
167
        return call_user_func_array('pcntl_sigtimedwait', func_get_args());
168
    }
169
170
    /**
171
     * Waits for signals
172
     *
173
     * @param array $set     Array of signals to wait for.
174
     * @param array $siginfo The siginfo parameter is set to an array containing
175
     *                       informations about the signal.
176
     *
177
     * @return int
178
     */
179
    public function sigwaitinfo(array $set, array &$siginfo = null) : int
0 ignored issues
show
Unused Code introduced by
The parameter $set is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $siginfo is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
180
    {
181
        return call_user_func_array('pcntl_sigwaitinfo', func_get_args());
182
    }
183
184
    /**
185
     * Retrieve the system error message associated with the given errno
186
     *
187
     * @param int $errno
188
     *
189
     * @return string
190
     */
191
    public function strerror(int $errno) : string
192
    {
193
        return pcntl_strerror($errno);
194
    }
195
196
    /**
197
     * Waits on or returns the status of a forked child
198
     *
199
     * @param int $status  pcntl_wait will store status information
200
     *                     in the status parameter which can be
201
     *                     evaluated using the following functions:
202
     *                     pcntl_wifexited,
203
     *                     pcntl_wifstopped,
204
     *                     pcntl_wifsignaled,
205
     *                     pcntl_wexitstatus,
206
     *                     pcntl_wtermsig and
207
     *                     pcntl_wstopsig.
208
     * @param int $options If wait3 is available on your system (mostly BSD-style systems), you can
209
     *                     provide the optional options parameter.  If this
210
     *                     parameter is not provided, wait will be used for the system call.  If
211
     *                     wait3 is not available, providing a value for options
212
     *                     will have no effect. The value of options
213
     *                     is the value of zero or more of the following two constants
214
     *                     OR'ed together:
215
     *
216
     * Possible values for options
217
     *
218
     *
219
     *
220
     * WNOHANG
221
     *
222
     * Return immediately if no child has exited.
223
     *
224
     *
225
     *
226
     * WUNTRACED
227
     *
228
     * Return for children which are stopped, and whose status has
229
     * not been reported.
230
     *
231
     * @return int
232
     */
233
    public function wait(int &$status, int $options = null) : int
0 ignored issues
show
Unused Code introduced by
The parameter $status is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
234
    {
235
        return call_user_func_array('pcntl_wait', func_get_args());
236
    }
237
238
    /**
239
     * Waits on or returns the status of a forked child
240
     *
241
     * @param int $pid     The value of pid can be one of the following:
242
     *
243
     * possible values for pid
244
     *
245
     *
246
     *
247
     * -1
248
     *
249
     * wait for any child process whose process group ID is equal to
250
     * the absolute value of pid.
251
     *
252
     *
253
     *
254
     * -1
255
     *
256
     * wait for any child process; this is the same behaviour that
257
     * the wait function exhibits.
258
     *
259
     *
260
     *
261
     * 0
262
     *
263
     * wait for any child process whose process group ID is equal to
264
     * that of the calling process.
265
     *
266
     *
267
     *
268
     * 0
269
     *
270
     * wait for the child whose process ID is equal to the value of
271
     * pid.
272
     * @param int $status  pcntl_waitpid will store status information
273
     *                     in the status parameter which can be
274
     *                     evaluated using the following functions:
275
     *                     pcntl_wifexited,
276
     *                     pcntl_wifstopped,
277
     *                     pcntl_wifsignaled,
278
     *                     pcntl_wexitstatus,
279
     *                     pcntl_wtermsig and
280
     *                     pcntl_wstopsig.
281
     * @param int $options The value of options is the value of zero
282
     *                     or more of the following two global constants
283
     *                     OR'ed together:
284
     *
285
     * possible values for options
286
     *
287
     *
288
     *
289
     * WNOHANG
290
     *
291
     * return immediately if no child has exited.
292
     *
293
     *
294
     *
295
     * WUNTRACED
296
     *
297
     * return for children which are stopped, and whose status has
298
     * not been reported.
299
     *
300
     * @return int
301
     */
302
    public function waitpid(int $pid, int &$status, int $options = null) : int
0 ignored issues
show
Unused Code introduced by
The parameter $pid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $status is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
303
    {
304
        return call_user_func_array('pcntl_waitpid', func_get_args());
305
    }
306
307
    /**
308
     * Returns the return code of a terminated child
309
     *
310
     * @param int $status
311
     *
312
     * @return int
313
     */
314
    public function wexitstatus(int $status) : int
315
    {
316
        return pcntl_wexitstatus($status);
317
    }
318
319
    /**
320
     * Checks if status code represents a normal exit
321
     *
322
     * @param int $status
323
     *
324
     * @return bool
325
     */
326
    public function wifexited(int $status) : bool
327
    {
328
        return pcntl_wifexited($status);
329
    }
330
331
    /**
332
     * Checks whether the status code represents a termination due to a signal
333
     *
334
     * @param int $status
335
     *
336
     * @return bool
337
     */
338
    public function wifsignaled(int $status) : bool
339
    {
340
        return pcntl_wifsignaled($status);
341
    }
342
343
    /**
344
     * Checks whether the child process is currently stopped
345
     *
346
     * @param int $status
347
     *
348
     * @return bool
349
     */
350
    public function wifstopped(int $status) : bool
351
    {
352
        return pcntl_wifstopped($status);
353
    }
354
355
    /**
356
     * Returns the signal which caused the child to stop
357
     *
358
     * @param int $status
359
     *
360
     * @return int
361
     */
362
    public function wstopsig(int $status) : int
363
    {
364
        return pcntl_wstopsig($status);
365
    }
366
367
    /**
368
     * Returns the signal which caused the child to terminate
369
     *
370
     * @param int $status
371
     *
372
     * @return int
373
     */
374
    public function wtermsig(int $status) : int
375
    {
376
        return pcntl_wtermsig($status);
377
    }
378
379
}
380
381