略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pcntl_signal_get_handler

2024-11-14

pcntl_signal_get_handler

(PHP 7 >= 7.1.0, PHP 8)

pcntl_signal_get_handlerGet the current handler for specified signal

说明

pcntl_signal_get_handler(int $signal): callable|int

The pcntl_signal_get_handler() function will get the current handler for the specified signal.

参数

signal

The signal number.

返回值

This function may return an integer value that refers to SIG_DFL or SIG_IGN. If a custom handler has been set, that callable is returned.

更新日志

版本 说明
7.1.0 pcntl_signal_get_handler() has been added.

范例

示例 #1 pcntl_signal_get_handler() example

<?php
var_dump
(pcntl_signal_get_handler(SIGUSR1)); // Outputs: int(0)

function pcntl_test($signo) {}
pcntl_signal(SIGUSR1'pcntl_test');
var_dump(pcntl_signal_get_handler(SIGUSR1)); // Outputs: string(10) "pcntl_test"

pcntl_signal(SIGUSR1SIG_DFL);
var_dump(pcntl_signal_get_handler(SIGUSR1)); // Outputs: int(0)

pcntl_signal(SIGUSR1SIG_IGN);
var_dump(pcntl_signal_get_handler(SIGUSR1)); // Outputs: int(1)
?>

参见

add a noteadd a note

User Contributed Notes 2 notes

up
3
jrdbrndt at gmail dot com
4 years ago
It is worth noting that supplying an invalid signal number will trigger a warning and return false.
up
-1
MAL
1 year ago
If the signal handler is a Closure, the function itself is returned:

pcntl_signal(SIGHUP, function ($signo, $siginfo) {
    echo SIGHUP;
});

var_dump(pcntl_signal_get_handler(SIGHUP)); // Outputs: string(6) "SIGHUP"

官方地址:https://www.php.net/manual/en/function.pcntl-signal-get-handler.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3