You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 46106a2
Browse filesBrowse the repository at this point in the historyBrowse files
AMQP relies on heartbeat feature to make sure consumer is still there.
291
+
Basically consumer is expected to send heartbeat frames from time to time to RabbitMQ broker.
292
+
It is not possible to implement heartbeat feature in PHP, due to its synchronous nature.
293
+
You could read more about the issues in post: [Keeping RabbitMQ connections alive in PHP](https://blog.mollie.com/keeping-rabbitmq-connections-alive-in-php-b11cb657d5fb).
294
+
295
+
`enqueue/amqp-lib` address the issue by registering heartbeat call as a [tick callbacks](http://php.net/manual/en/function.register-tick-function.php).
296
+
To make it work you have to wrapp your long running task by `decalre(ticks=1) {}`.
297
+
The number of ticks could be adjusted to your needs.
298
+
Calling it at every tick is not good.
299
+
300
+
Please note that it does not fix heartbeat issue if you spent most of the time on IO operation.
301
+
302
+
Example:
303
+
304
+
```php
305
+
<?php
306
+
307
+
use Enqueue\AmqpLib\AmqpConnectionFactory;
308
+
use Interop\Amqp\AmqpConsumer;
309
+
use Interop\Amqp\AmqpMessage;
310
+
311
+
$context = (new AmqpConnectionFactory('amqp:?heartbeat_on_tick=1'))->createContext();
// cycle does something for a long time, much longer than amqp heartbeat.
322
+
}
323
+
}
324
+
325
+
$consumer->acknowledge($message);
326
+
327
+
return true;
328
+
});
329
+
330
+
$subscriptionConsumer->consume(10000);
331
+
332
+
333
+
function fetchHugeSet(): array {};
334
+
```
335
+
336
+
Fixes partly `Invalid frame type 65` issue.
337
+
338
+
```
339
+
Error: Uncaught PhpAmqpLib\Exception\AMQPRuntimeException: Invalid frame type 65 in /some/path/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php:528
340
+
```
341
+
342
+
Fixes partly `Broken pipe or closed connection` issue.
343
+
344
+
```
345
+
PHP Fatal error: Uncaught exception 'PhpAmqpLib\Exception\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /some/path/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190
0 commit comments