Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Yii2 Queue Extension Change Log
- Enh #503: All dependent packages for supported drivers have been updated to the latest versions (@s1lver)
- Enh #503: The `opis/closure` package did not support PHP 8.1 and was replaced by the `laravel/serializable-closure` package (@s1lver)
- Enh #544: Applying Yii2 coding standards (@s1lver)
- Enh #552: Move signal handling from AMQP Interop queue component to controller (@snewer)
Comment thread
snewer marked this conversation as resolved.

2.3.8 January 08, 2026
----------------------
Expand Down
32 changes: 32 additions & 0 deletions src/drivers/amqp_interop/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ class Command extends CliCommand
*/
public CliQueue $queue;

/**
* @inheritdoc
*/
public function init(): void
{
parent::init();

// https://github.com/yiisoft/yii2-queue/issues/379
if (extension_loaded('pcntl') && function_exists('pcntl_signal')) {
// https://github.com/php-amqplib/php-amqplib#unix-signals
$signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP];

foreach ($signals as $signal) {
/** @var (callable(int):void)|int|null $oldHandler */
$oldHandler = null;
// This got added in php 7.1 and might not exist on all supported versions
if (function_exists('pcntl_signal_get_handler')) {
$oldHandler = pcntl_signal_get_handler($signal);
}

pcntl_signal($signal, static function ($signal) use ($oldHandler) {
if ($oldHandler && is_callable($oldHandler)) {
$oldHandler($signal);
}

pcntl_signal($signal, SIG_DFL);
posix_kill(posix_getpid(), $signal);
Comment thread
snewer marked this conversation as resolved.
});
}
}
}

/**
* @inheritdoc
*/
Expand Down
22 changes: 0 additions & 22 deletions src/drivers/amqp_interop/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,28 +294,6 @@ public function init(): void
Event::on(BaseApp::class, BaseApp::EVENT_AFTER_REQUEST, function () {
$this->close();
});

if (extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7) {
// https://github.com/php-amqplib/php-amqplib#unix-signals
$signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP];

foreach ($signals as $signal) {
$oldHandler = null;
// This got added in php 7.1 and might not exist on all supported versions
if (function_exists('pcntl_signal_get_handler')) {
$oldHandler = pcntl_signal_get_handler($signal);
}

pcntl_signal($signal, static function ($signal) use ($oldHandler) {
if ($oldHandler && is_callable($oldHandler)) {
$oldHandler($signal);
}

pcntl_signal($signal, SIG_DFL);
posix_kill(posix_getpid(), $signal);
});
}
}
}

/**
Expand Down
Loading