diff -Nru php-amqplib-2.6.3/CHANGELOG.md php-amqplib-2.7.0/CHANGELOG.md --- php-amqplib-2.6.3/CHANGELOG.md 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/CHANGELOG.md 2017-08-03 22:06:21.000000000 +0000 @@ -4,6 +4,30 @@ ## [Unreleased] +## 2.7.0-rc1 - 2017-05-22 +### Added +- Increased overall test coverage +- Bring heartbeat support to socket connection +- Add message delivery tag for publisher confirms +- Add support for serializing DateTimeImmutable objects + +### Fixed +- Fixed infinite loop on reconnect - check_heartbeat +- Fixed signal handling exit example +- Fixed exchange_unbind arguments +- Fixed invalid annotation for channel_id +- Fixed socket null error on php 5.3 version +- Fixed timeout parameters on HHVM before calling stream_select + +### Changed +- declare(ticks=1) no longer needed after PHP5.3 / amqplib 2.4.1 + +### Enhancements +- Add extensions requirements to README.md +- Add PHP 7.1 to Travis build +- Reduce memory usage in StreamIO::write() +- Re-enable heartbeats after reconnection + ## 2.6.3 - 2016-04-11 ### Added diff -Nru php-amqplib-2.6.3/debian/changelog php-amqplib-2.7.0/debian/changelog --- php-amqplib-2.6.3/debian/changelog 2016-04-15 13:51:58.000000000 +0000 +++ php-amqplib-2.7.0/debian/changelog 2017-10-12 18:22:17.000000000 +0000 @@ -1,3 +1,9 @@ +php-amqplib (2.7.0-1) unstable; urgency=medium + + * Update Standards-Version to 4.1.1 + + -- David Prévot Thu, 12 Oct 2017 08:22:17 -1000 + php-amqplib (2.6.3-1) unstable; urgency=medium [ Todoshchenko Andrey ] @@ -39,7 +45,6 @@ php-amqplib (2.6.1-1) unstable; urgency=medium - [ John Kelly ] * The start of a changelog * Make changes for new maintainers and package diff -Nru php-amqplib-2.6.3/debian/control php-amqplib-2.7.0/debian/control --- php-amqplib-2.6.3/debian/control 2016-04-15 13:49:14.000000000 +0000 +++ php-amqplib-2.7.0/debian/control 2017-10-12 18:21:23.000000000 +0000 @@ -4,7 +4,7 @@ Maintainer: Debian PHP PEAR Maintainers Uploaders: David Prévot Build-Depends: debhelper (>= 9), phpab, pkg-php-tools (>= 1.7~) -Standards-Version: 3.9.8 +Standards-Version: 4.1.1 Vcs-Git: git://anonscm.debian.org/pkg-php/php-amqplib.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-php/php-amqplib.git Homepage: https://github.com/php-amqplib/php-amqplib diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Channel/AbstractChannel.php php-amqplib-2.7.0/PhpAmqpLib/Channel/AbstractChannel.php --- php-amqplib-2.6.3/PhpAmqpLib/Channel/AbstractChannel.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Channel/AbstractChannel.php 2017-08-03 22:06:21.000000000 +0000 @@ -255,7 +255,6 @@ $this->wait_content_reader->reuse(mb_substr($payload, 0, 12, 'ASCII')); - // $payload_reader = new AMQPReader(substr($payload,0,12)); $class_id = $this->wait_content_reader->read_short(); $weight = $this->wait_content_reader->read_short(); diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Channel/AMQPChannel.php php-amqplib-2.7.0/PhpAmqpLib/Channel/AMQPChannel.php --- php-amqplib-2.6.3/PhpAmqpLib/Channel/AMQPChannel.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Channel/AMQPChannel.php 2017-08-03 22:06:21.000000000 +0000 @@ -476,11 +476,12 @@ * @param string $destination * @param string $source * @param string $routing_key + * @param bool $nowait * @param array $arguments * @param int $ticket * @return mixed */ - public function exchange_unbind($destination, $source, $routing_key = '', $arguments = null, $ticket = null) + public function exchange_unbind($destination, $source, $routing_key = '', $nowait = false, $arguments = null, $ticket = null) { $arguments = $this->getArguments($arguments); $ticket = $this->getTicket($ticket); @@ -490,6 +491,7 @@ $destination, $source, $routing_key, + $nowait, $arguments ); @@ -806,6 +808,7 @@ } else { $message = $this->get_and_unset_message($delivery_tag); + $message->delivery_info['delivery_tag'] = $delivery_tag; $this->dispatch_to_handler($handler, array($message)); } } diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Connection/AbstractConnection.php php-amqplib-2.7.0/PhpAmqpLib/Connection/AbstractConnection.php --- php-amqplib-2.6.3/PhpAmqpLib/Connection/AbstractConnection.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Connection/AbstractConnection.php 2017-08-03 22:06:21.000000000 +0000 @@ -215,6 +215,11 @@ $host = $this->x_open($this->vhost, '', $this->insist); if (!$host) { + //Reconnected + if ($this->io instanceof StreamIO) + { + $this->getIO()->reenableHeartbeat(); + } return null; // we weren't redirected } @@ -593,7 +598,7 @@ * Fetches a channel object identified by the numeric channel_id, or * create that object if it doesn't already exist. * - * @param string $channel_id + * @param int $channel_id * @return AMQPChannel */ public function channel($channel_id = null) @@ -624,7 +629,7 @@ $this->io->disableHeartbeat(); } - if (!$this->protocolWriter || !$this->isConnected()) { + if (empty($this->protocolWriter) || !$this->isConnected()) { return null; } diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Connection/AMQPLazyConnection.php php-amqplib-2.7.0/PhpAmqpLib/Connection/AMQPLazyConnection.php --- php-amqplib-2.6.3/PhpAmqpLib/Connection/AMQPLazyConnection.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Connection/AMQPLazyConnection.php 2017-08-03 22:06:21.000000000 +0000 @@ -30,7 +30,7 @@ */ protected function getIO() { - if (!$this->io) { + if (empty($this->io)) { $this->connect(); } diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Connection/AMQPLazySocketConnection.php php-amqplib-2.7.0/PhpAmqpLib/Connection/AMQPLazySocketConnection.php --- php-amqplib-2.6.3/PhpAmqpLib/Connection/AMQPLazySocketConnection.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Connection/AMQPLazySocketConnection.php 2017-08-03 22:06:21.000000000 +0000 @@ -34,7 +34,7 @@ */ protected function getIO() { - if (!$this->io) { + if (empty($this->io)) { $this->connect(); } @@ -50,4 +50,4 @@ { return false; } -} \ No newline at end of file +} diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Connection/AMQPSocketConnection.php php-amqplib-2.7.0/PhpAmqpLib/Connection/AMQPSocketConnection.php --- php-amqplib-2.6.3/PhpAmqpLib/Connection/AMQPSocketConnection.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Connection/AMQPSocketConnection.php 2017-08-03 22:06:21.000000000 +0000 @@ -15,8 +15,10 @@ * @param string $login_method * @param null $login_response * @param string $locale - * @param float $timeout + * @param float $read_timeout * @param bool $keepalive + * @param int $write_timeout + * @param int $heartbeat */ public function __construct( $host, @@ -28,10 +30,12 @@ $login_method = 'AMQPLAIN', $login_response = null, $locale = 'en_US', - $timeout = 3, - $keepalive = false + $read_timeout = 3, + $keepalive = false, + $write_timeout = 3, + $heartbeat = 0 ) { - $io = new SocketIO($host, $port, $timeout, $keepalive); + $io = new SocketIO($host, $port, $read_timeout, $keepalive, $write_timeout, $heartbeat); parent::__construct( $user, @@ -41,7 +45,8 @@ $login_method, $login_response, $locale, - $io + $io, + $heartbeat ); } } diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Helper/DebugHelper.php php-amqplib-2.7.0/PhpAmqpLib/Helper/DebugHelper.php --- php-amqplib-2.6.3/PhpAmqpLib/Helper/DebugHelper.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Helper/DebugHelper.php 2017-08-03 22:06:21.000000000 +0000 @@ -7,7 +7,12 @@ * @var bool */ protected $debug; - + + /** + * @var resource + */ + protected $debug_output; + /** * @var string */ @@ -17,7 +22,10 @@ * @param string $PROTOCOL_CONSTANTS_CLASS */ public function __construct($PROTOCOL_CONSTANTS_CLASS) { + if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'w')); + $this->debug = defined('AMQP_DEBUG') ? AMQP_DEBUG : false; + $this->debug_output = defined('AMQP_DEBUG_OUTPUT') ? AMQP_DEBUG_OUTPUT : STDOUT; $this->PROTOCOL_CONSTANTS_CLASS = $PROTOCOL_CONSTANTS_CLASS; } @@ -101,6 +109,6 @@ * @param string $s */ protected function print_msg($s) { - echo $s . PHP_EOL; + fwrite($this->debug_output, $s . PHP_EOL); } } diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Wire/AMQPAbstractCollection.php php-amqplib-2.7.0/PhpAmqpLib/Wire/AMQPAbstractCollection.php --- php-amqplib-2.6.3/PhpAmqpLib/Wire/AMQPAbstractCollection.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Wire/AMQPAbstractCollection.php 2017-08-03 22:06:21.000000000 +0000 @@ -207,7 +207,10 @@ $val = $this->encodeBool($val); } elseif (is_null($val)) { $val = $this->encodeVoid(); + } elseif ($val instanceof \DateTimeInterface) { + $val = array(self::T_TIMESTAMP, $val->getTimestamp()); } elseif ($val instanceof \DateTime) { + // PHP <= 5.4 has no DateTimeInterface $val = array(self::T_TIMESTAMP, $val->getTimestamp()); } elseif ($val instanceof AMQPDecimal) { $val = array(self::T_DECIMAL, $val); diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Wire/AMQPReader.php php-amqplib-2.7.0/PhpAmqpLib/Wire/AMQPReader.php --- php-amqplib-2.6.3/PhpAmqpLib/Wire/AMQPReader.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Wire/AMQPReader.php 2017-08-03 22:06:21.000000000 +0000 @@ -59,7 +59,7 @@ { parent::__construct(); - $this->str = $str; + $this->str = is_string($str) ? $str : ''; $this->str_length = mb_strlen($this->str, 'ASCII'); $this->io = $io; $this->offset = 0; @@ -173,7 +173,7 @@ */ public function read_bit() { - if (!$this->bitcount) { + if (empty($this->bitcount)) { $this->bits = ord($this->rawread(1)); $this->bitcount = 8; } @@ -262,7 +262,7 @@ $this->bitcount = $this->bits = 0; list(, $res) = unpack('N', $this->rawread(4)); - return !$this->is64bits && self::getLongMSB($res) ? sprintf('%u', $res) : $res; + return empty($this->is64bits) && self::getLongMSB($res) ? sprintf('%u', $res) : $res; } /** @@ -290,7 +290,7 @@ list(, $hi, $lo) = unpack('N2', $this->rawread(8)); $msb = self::getLongMSB($hi); - if (!$this->is64bits) { + if (empty($this->is64bits)) { if ($msb) { $hi = sprintf('%u', $hi); } diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Wire/AMQPWriter.php php-amqplib-2.7.0/PhpAmqpLib/Wire/AMQPWriter.php --- php-amqplib-2.6.3/PhpAmqpLib/Wire/AMQPWriter.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Wire/AMQPWriter.php 2017-08-03 22:06:21.000000000 +0000 @@ -233,7 +233,7 @@ } //Numeric strings >PHP_INT_MAX on 32bit are casted to PHP_INT_MAX, damn PHP - if (!$this->is64bits && is_string($n)) { + if (empty($this->is64bits) && is_string($n)) { $n = (float) $n; } $this->out .= pack('N', $n); diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Wire/GenericContent.php php-amqplib-2.7.0/PhpAmqpLib/Wire/GenericContent.php --- php-amqplib-2.6.3/PhpAmqpLib/Wire/GenericContent.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Wire/GenericContent.php 2017-08-03 22:06:21.000000000 +0000 @@ -9,7 +9,7 @@ */ abstract class GenericContent { - /** @var AMQPChannel[] */ + /** @var array */ public $delivery_info = array(); /** @var array Final property definitions */ @@ -34,11 +34,7 @@ */ public function __construct($properties, $propertyTypes = null) { - $this->prop_types = self::$propertyDefinitions; - - if (!empty($propertyTypes)) { - $this->prop_types = $propertyTypes; - } + $this->prop_types = !empty($propertyTypes) ? $propertyTypes : self::$propertyDefinitions; if (!empty($properties)) { $this->properties = array_intersect_key($properties, $this->prop_types); diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Wire/IO/SocketIO.php php-amqplib-2.7.0/PhpAmqpLib/Wire/IO/SocketIO.php --- php-amqplib-2.6.3/PhpAmqpLib/Wire/IO/SocketIO.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Wire/IO/SocketIO.php 2017-08-03 22:06:21.000000000 +0000 @@ -4,6 +4,7 @@ use PhpAmqpLib\Exception\AMQPIOException; use PhpAmqpLib\Exception\AMQPRuntimeException; use PhpAmqpLib\Helper\MiscHelper; +use PhpAmqpLib\Wire\AMQPWriter; class SocketIO extends AbstractIO { @@ -14,7 +15,19 @@ protected $port; /** @var float */ - protected $timeout; + protected $send_timeout; + + /** @var float */ + protected $read_timeout; + + /** @var int */ + protected $heartbeat; + + /** @var float */ + protected $last_read; + + /** @var float */ + protected $last_write; /** @var resource */ private $sock; @@ -25,14 +38,18 @@ /** * @param string $host * @param int $port - * @param float $timeout + * @param float $read_timeout * @param bool $keepalive + * @param float|null $write_timeout if null defaults to read timeout + * @param int $heartbeat how often to send heartbeat. 0 means off */ - public function __construct($host, $port, $timeout, $keepalive = false) + public function __construct($host, $port, $read_timeout, $keepalive = false, $write_timeout = null, $heartbeat = 0) { $this->host = $host; $this->port = $port; - $this->timeout = $timeout; + $this->read_timeout = $read_timeout; + $this->send_timeout = $write_timeout ?: $read_timeout; + $this->heartbeat = $heartbeat; $this->keepalive = $keepalive; } @@ -45,9 +62,10 @@ { $this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - list($sec, $uSec) = MiscHelper::splitSecondsMicroseconds($this->timeout); - socket_set_option($this->sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sec, 'usec' => $uSec)); + list($sec, $uSec) = MiscHelper::splitSecondsMicroseconds($this->send_timeout); socket_set_option($this->sock, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $sec, 'usec' => $uSec)); + list($sec, $uSec) = MiscHelper::splitSecondsMicroseconds($this->read_timeout); + socket_set_option($this->sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sec, 'usec' => $uSec)); if (!socket_connect($this->sock, $this->host, $this->port)) { $errno = socket_last_error($this->sock); @@ -92,18 +110,17 @@ */ public function read($n) { + if (is_null($this->sock)) { + throw new AMQPRuntimeException(sprintf( + 'Socket was null! Last SocketError was: %s', + socket_strerror(socket_last_error()) + )); + } $res = ''; $read = 0; - $buf = socket_read($this->sock, $n); while ($read < $n && $buf !== '' && $buf !== false) { - // Null sockets are invalid, throw exception - if (is_null($this->sock)) { - throw new AMQPRuntimeException(sprintf( - 'Socket was null! Last SocketError was: %s', - socket_strerror(socket_last_error()) - )); - } + $this->check_heartbeat(); $read += mb_strlen($buf, 'ASCII'); $res .= $buf; @@ -118,12 +135,15 @@ )); } + $this->last_read = microtime(true); + return $res; } /** * @param string $data - * @return mixed|void + * @return void + * * @throws \PhpAmqpLib\Exception\AMQPIOException * @throws \PhpAmqpLib\Exception\AMQPRuntimeException */ @@ -159,6 +179,8 @@ break; } } + + $this->last_write = microtime(true); } public function close() @@ -167,6 +189,8 @@ socket_close($this->sock); } $this->sock = null; + $this->last_read = null; + $this->last_write = null; } /** @@ -194,4 +218,40 @@ socket_set_option($this->sock, SOL_SOCKET, SO_KEEPALIVE, 1); } + + /** + * Heartbeat logic: check connection health here + */ + protected function check_heartbeat() + { + // ignore unless heartbeat interval is set + if ($this->heartbeat !== 0 && $this->last_read && $this->last_write) { + $t = microtime(true); + $t_read = round($t - $this->last_read); + $t_write = round($t - $this->last_write); + + // server has gone away + if (($this->heartbeat * 2) < $t_read) { + $this->reconnect(); + } + + // time for client to send a heartbeat + if (($this->heartbeat / 2) < $t_write) { + $this->write_heartbeat(); + } + } + } + + /** + * Sends a heartbeat message + */ + protected function write_heartbeat() + { + $pkt = new AMQPWriter(); + $pkt->write_octet(8); + $pkt->write_short(0); + $pkt->write_long(0); + $pkt->write_octet(0xCE); + $this->write($pkt->getvalue()); + } } diff -Nru php-amqplib-2.6.3/PhpAmqpLib/Wire/IO/StreamIO.php php-amqplib-2.7.0/PhpAmqpLib/Wire/IO/StreamIO.php --- php-amqplib-2.6.3/PhpAmqpLib/Wire/IO/StreamIO.php 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/PhpAmqpLib/Wire/IO/StreamIO.php 2017-08-03 22:06:21.000000000 +0000 @@ -42,6 +42,9 @@ /** @var array */ protected $last_error; + /** @var int */ + private $initial_heartbeat; + /** @var resource */ private $sock; @@ -81,6 +84,7 @@ $this->context = $context; $this->keepalive = $keepalive; $this->heartbeat = $heartbeat; + $this->initial_heartbeat = $heartbeat; $this->canSelectNull = true; $this->canDispatchPcntlSignal = $this->isPcntlSignalEnabled(); @@ -197,12 +201,12 @@ */ public function read($len) { + $this->check_heartbeat(); + $read = 0; $data = ''; while ($read < $len) { - $this->check_heartbeat(); - if (!is_resource($this->sock) || feof($this->sock)) { throw new AMQPRuntimeException('Broken pipe or closed connection'); } @@ -278,7 +282,7 @@ // September 2002: // http://comments.gmane.org/gmane.comp.encryption.openssl.user/4361 try { - $buffer = fwrite($this->sock, $data, 8192); + $buffer = fwrite($this->sock, mb_substr($data, $written, 8192, 'ASCII'), 8192); } catch (\ErrorException $e) { restore_error_handler(); throw $e; @@ -298,10 +302,6 @@ } $written += $buffer; - - if ($buffer > 0) { - $data = mb_substr($data, $buffer, mb_strlen($data, 'ASCII') - $buffer, 'ASCII'); - } } $this->last_write = microtime(true); @@ -380,6 +380,8 @@ fclose($this->sock); } $this->sock = null; + $this->last_read = null; + $this->last_write = null; } /** @@ -405,11 +407,17 @@ */ public function select($sec, $usec) { + $this->check_heartbeat(); + $read = array($this->sock); $write = null; $except = null; $result = false; + if (defined('HHVM_VERSION')) { + $usec = is_int($usec) ? $usec : 0; + } + set_error_handler(array($this, 'error_handler')); try { $result = stream_select($read, $write, $except, $sec, $usec); @@ -459,4 +467,14 @@ return $this; } + + /** + * @return $this + */ + public function reenableHeartbeat() + { + $this->heartbeat = $this->initial_heartbeat; + + return $this; + } } diff -Nru php-amqplib-2.6.3/README.md php-amqplib-2.7.0/README.md --- php-amqplib-2.6.3/README.md 2016-04-11 14:30:01.000000000 +0000 +++ php-amqplib-2.7.0/README.md 2017-08-03 22:06:21.000000000 +0000 @@ -7,20 +7,26 @@ [![Quality Score][ico-code-quality]][link-code-quality] [![Total Downloads][ico-downloads]][link-downloads] -This library is a _pure PHP_ implementation of the AMQP protocol. It's been tested against [RabbitMQ](http://www.rabbitmq.com/). +This library is a _pure PHP_ implementation of the [AMQP 0-9-1 protocol](http://www.rabbitmq.com/tutorials/amqp-concepts.html). +It's been tested against [RabbitMQ](http://www.rabbitmq.com/). **Requirements: PHP 5.3** due to the use of `namespaces`. +**Requirements: bcmath and mbstring extensions** This library utilizes the bcmath and mbstring PHP extensions. The installation steps vary per PHP version and the underlying OS. The following example shows how to add to an existing PHP installation on Ubuntu 15.10: + +sudo apt-get install php7.0-mbstring +sudo apt-get install php7.0-bcmath + The library was used for the PHP examples of [RabbitMQ in Action](http://manning.com/videla/) and the [official RabbitMQ tutorials](http://www.rabbitmq.com/tutorials/tutorial-one-php.html). Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. -## New Maintainers (02/10/2016) ## +## Project Maintainers -Thanks to [videlalvaro](https://github.com/videlalvaro) for his hard work in maintaining php-amqplib! He's done a fantastic job -and has left big shoes to fill. +Thanks to [videlalvaro](https://github.com/videlalvaro) and [postalservice14](https://github.com/postalservice14) for their hard work maintaining php-amqplib! The library wouldn't be where it is without them. -The package will now be maintained by [postalservice14](https://github.com/postalservice14) and [nubeiro](https://github.com/nubeiro). +The package is now maintained by [nubeiro](https://github.com/nubeiro) and several Pivotal engineers +working on RabbitMQ and related projects. ## Supported RabbitMQ Versions ## @@ -172,7 +178,7 @@ By default, no truncation will occur. To disable truncation on a Channel that has had it enabled, pass `0` (or `null`) to `AMQPChannel::setBodySizeLimit()`. -##UNIX Signals## +## UNIX Signals ## If you have installed [PCNTL extension](http://www.php.net/manual/en/book.pcntl.php) dispatching of signal will be handled when consumer is not processing message. @@ -183,8 +189,8 @@ case \SIGUSR1: case \SIGINT: // some stuff before stop consumer e.g. delete lock etc - exit(0); - break; + pcntl_signal($signal, SIG_DFL); // restore handler + posix_kill(posix_getpid(), $signal); // kill self with signal, see https://www.cons.org/cracauer/sigint.html case \SIGHUP: // some stuff to restart consumer break; @@ -193,12 +199,10 @@ } }; -declare(ticks = 1) { - pcntl_signal(\SIGTERM, $pcntlHandler); - pcntl_signal(\SIGINT, $pcntlHandler); - pcntl_signal(\SIGUSR1, $pcntlHandler); - pcntl_signal(\SIGHUP, $pcntlHandler); -} +pcntl_signal(\SIGTERM, $pcntlHandler); +pcntl_signal(\SIGINT, $pcntlHandler); +pcntl_signal(\SIGUSR1, $pcntlHandler); +pcntl_signal(\SIGHUP, $pcntlHandler); ``` To disable this feature just define constant `AMQP_WITHOUT_SIGNALS` as `true` @@ -292,7 +296,7 @@ Author: Vadim Zaliva [ico-version]: https://img.shields.io/packagist/v/php-amqplib/php-amqplib.svg?style=flat-square -[ico-license]: https://img.shields.io/badge/license-LGPL-brightgreen.svg?style=flat-square +[ico-license]: https://img.shields.io/badge/license-LGPL_2.1-brightgreen.svg?style=flat-square [ico-travis]: https://img.shields.io/travis/php-amqplib/php-amqplib/master.svg?style=flat-square [ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/php-amqplib/php-amqplib.svg?style=flat-square [ico-code-quality]: https://img.shields.io/scrutinizer/g/php-amqplib/php-amqplib.svg?style=flat-square