4

我正在从 CLI 运行 php 脚本,并且我想在脚本用 ctrl + c 停止时执行一个函数。我试过这个:

<?php

declare(ticks = 1);

function sigint() {
    echo 'This is the end';
    exit;
}

pcntl_signal(SIGTERM, 'sigint');

$i = 1;

do {

    echo $i++ . ' ';

    sleep(1);

} while (TRUE);

但它不起作用。我怎样才能做到这一点?

4

1 回答 1

1

在 中附加处理程序时pcntl_signal,请使用SIGINT而不是SIGTERM

于 2016-02-18T14:53:10.780 回答