Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pcntl_signal_dispatch after job finish for php extension #485

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Ignore signal for amqp extension while job is executing
  • Loading branch information
dimansuvorlinda committed Jun 18, 2023
commit 01a32b267aa6b25b130e222558540d3263fd59b6
28 changes: 28 additions & 0 deletions src/drivers/amqp_interop/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@ public function listen()
return true;
}

// Ignore signal for amqp extension while job is executing
if (
extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7 &&
$this->driver === self::ENQUEUE_AMQP_EXT
) {
$signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP];

foreach ($signals as $signal) {
pcntl_signal($signal, static function ($signal) {
pcntl_signal($signal, SIG_DFL);
posix_kill(posix_getpid(), $signal);
});
}
}

$ttr = $message->getProperty(self::TTR);
$attempt = $message->getProperty(self::ATTEMPT, 1);

Expand All @@ -336,6 +351,19 @@ public function listen()
$this->redeliver($message);
}

// For amqp extension: restore default signal handlers
if (
extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7 &&
$this->driver === self::ENQUEUE_AMQP_EXT
) {
pcntl_signal_dispatch();

$signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP];
foreach ($signals as $signal) {
pcntl_signal($signal, SIG_DFL);
}
}

return true;
};

Expand Down