class ProcessUtil

Class ProcessUtil

Properties

static array $signalMap

Methods

static bool
hasPcntl()

No description

static bool
hasPosix()

No description

static array
run(string $command, string $cwd = null)

run a command. it is support windows

static int
daemonRun(Closure $beforeQuit = null)

Daemon, detach and run in the background

static int|string
runInBackground(string $cmd)

run a command in background

static array|false
multi(int $number, callable $onStart = null, callable $onError = null)

No description

static array|false
forks(int $number, callable $onStart = null, callable $onError = null)

fork/create multi child processes.

static array|false
create(callable $onStart = null, callable $onError = null, int $id = 0)

No description

static array|false
fork(callable $onStart = null, callable $onError = null, int $id = 0)

fork/create a child process.

static bool
wait(callable $onExit)

wait child exit.

static bool
stopWorkers(array $children, int $signal = SIGTERM, array $events = [])

Stops all running children

static bool
kill(int $pid, bool $force = false, int $timeout = 3)

send kill signal to the process

static bool
killAndWait(int $pid, $error = null, $name = 'process', bool $force = false, int $waitTime = 10)

Do shutdown process and wait it exit.

static string
killByName(string $name, int $sigNo = 9)

杀死所有进程

static bool
isRunning(int $pid)

No description

static 
quit(int $code = 0)

exit

static bool
sendSignal(int $pid, int $signal, int $timeout = 0)

send signal to the process

static bool
installSignal(int $signal, callable $handler)

install signal

static bool
dispatchSignal()

dispatch signal

static int
getPid()

get current process id

static int
getPidByFile(string $file, bool $checkLive = false)

get Pid from File

static array
getCurrentUser()

Get unix user of current process.

static bool|int
afterDo(int $seconds, callable $handler)

No description

static bool
setName(string $title)

Set process title.

static bool
setTitle(string $title)

Set process title.

static 
changeScriptOwner(string $user, string $group = '')

Set unix user and group for current process script.

Details

at line 30
static bool hasPcntl()

Return Value

bool

at line 38
static bool hasPosix()

Return Value

bool

at line 49
static array run(string $command, string $cwd = null)

run a command. it is support windows

Parameters

string $command
string $cwd

Return Value

array

at line 87
static int daemonRun(Closure $beforeQuit = null)

Daemon, detach and run in the background

Parameters

Closure $beforeQuit

Return Value

int Return new process PID

at line 128
static int|string runInBackground(string $cmd)

run a command in background

Parameters

string $cmd

Return Value

int|string

at line 146
static array|false multi(int $number, callable $onStart = null, callable $onError = null)

Parameters

int $number
callable $onStart
callable $onError

Return Value

array|false

See also

ProcessUtil::forks

at line 158
static array|false forks(int $number, callable $onStart = null, callable $onError = null)

fork/create multi child processes.

Parameters

int $number
callable $onStart Will running on the child processes.
callable $onError

Return Value

array|false

at line 185
static array|false create(callable $onStart = null, callable $onError = null, int $id = 0)

Parameters

callable $onStart
callable $onError
int $id

Return Value

array|false

See also

ProcessUtil::fork

at line 197
static array|false fork(callable $onStart = null, callable $onError = null, int $id = 0)

fork/create a child process.

Parameters

callable $onStart Will running on the child process start.
callable $onError
int $id The process index number. will use forks()

Return Value

array|false

at line 235
static bool wait(callable $onExit)

wait child exit.

Parameters

callable $onExit

Return Value

bool

at line 279
static bool stopWorkers(array $children, int $signal = SIGTERM, array $events = [])

Stops all running children

Parameters

array $children [ 'pid' => [ 'id' => worker id ], ... ... ]
int $signal
array $events [ 'beforeStops' => function ($sigText) { echo "Stopping processes({$sigText}) ...\n"; }, 'beforeStop' => function ($pid, $info) { echo "Stopping process(PID:$pid)\n"; } ]

Return Value

bool

at line 321
static bool kill(int $pid, bool $force = false, int $timeout = 3)

send kill signal to the process

Parameters

int $pid
bool $force
int $timeout

Return Value

bool

at line 335
static bool killAndWait(int $pid, $error = null, $name = 'process', bool $force = false, int $waitTime = 10)

Do shutdown process and wait it exit.

Parameters

int $pid
$error
$name
bool $force
int $waitTime

Return Value

bool

at line 384
static string killByName(string $name, int $sigNo = 9)

杀死所有进程

Parameters

string $name
int $sigNo

Return Value

string

at line 396
static bool isRunning(int $pid)

Parameters

int $pid

Return Value

bool

at line 405
static quit(int $code = 0)

exit

Parameters

int $code

at line 421
static bool sendSignal(int $pid, int $signal, int $timeout = 0)

send signal to the process

Parameters

int $pid
int $signal
int $timeout

Return Value

bool

at line 467
static bool installSignal(int $signal, callable $handler)

install signal

Parameters

int $signal e.g: SIGTERM SIGINT(Ctrl+C) SIGUSR1 SIGUSR2 SIGHUP
callable $handler

Return Value

bool

at line 480
static bool dispatchSignal()

dispatch signal

Return Value

bool

at line 498
static int getPid()

get current process id

Return Value

int

at line 509
static int getPidByFile(string $file, bool $checkLive = false)

get Pid from File

Parameters

string $file
bool $checkLive

Return Value

int

at line 529
static array getCurrentUser()

Get unix user of current process.

Return Value

array

at line 539
static bool|int afterDo(int $seconds, callable $handler)

Parameters

int $seconds
callable $handler

Return Value

bool|int

at line 564
static bool setName(string $title)

Set process title.

Parameters

string $title

Return Value

bool

at line 574
static bool setTitle(string $title)

Set process title.

Parameters

string $title

Return Value

bool

at line 593
static changeScriptOwner(string $user, string $group = '')

Set unix user and group for current process script.

Parameters

string $user
string $group

Exceptions

RuntimeException