【问题标题】:PHP - Issue with pcntl in PHP 7.0+. Potential bugPHP - PHP 7.0+ 中的 pcntl 问题。潜在的错误
【发布时间】:2017-08-24 15:44:39
【问题描述】:

我在 PHP 7.0+ 中遇到了 pcntl 信号处理的问题。问题是在某些情况下没有安排警报。

以下示例适用于 PHP 5.6,但不适用于 PHP 7.0 或 7.1。

文件.php

require_once('file2.php');

declare(ticks = 1);

// Add an alarm listener
pcntl_signal(SIGALRM, function() {
    var_dump("Triggered");

    // Re-schedule the alarm
    pcntl_alarm(5);
});

// Schedule the initial alarm
pcntl_alarm(5);

test();

file2.php

function test() {
    while(true) {
        sleep(2);
    }
}

在 PHP 5.6 和 7.0+ 中都可以使用代码段。如果我们将代码合并到一个文件中,那么它就可以工作了。

declare(ticks = 1);

// Add a alarm listener
pcntl_signal(SIGALRM, function() {
    var_dump("here");

    // Re-schedule the alarm to be triggered
    pcntl_alarm(5);
});

// Set the initial alarm
pcntl_alarm(5);

function test() {
    while(true) {
        sleep(2);
    }
}

test();

【问题讨论】:

标签: php php-7 php-5.6 pcntl


【解决方案1】:

问题与https://bugs.php.net/bug.php?id=71448#1463246578有关。

7.1 中引入的 pcntl_async_signals() 解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    相关资源
    最近更新 更多