Recommend this page to a friend! |
Classes of walid laggoune | QPHP | src/vendor/pda/pheanstalk/README.md | Download |
|
DownloadPheanstalkPheanstalk is a pure PHP 7.1+ client for the [beanstalkd workqueue][1]. It has been actively developed, and used in production by many, since late 2008. Created by [Paul Annesley][2], Pheanstalk is rigorously unit tested and written using encapsulated, maintainable object oriented design. Community feedback, bug reports and patches has led to a stable 1.0 release in 2010, a 2.0 release in 2013, and a 3.0 release in 2014. Pheanstalk 3.0 introduces PHP namespaces, PSR-1 and PSR-2 coding standards, and PSR-4 autoloader standard. beanstalkd up to the latest version 1.10 is supported. All commands and responses specified in the [protocol documentation][4] for beanstalkd 1.3 are implemented. [1]: https://beanstalkd.github.io/ [2]: https://paul.annesley.cc/ [3]: https://github.com/sammousa [4]: https://github.com/kr/beanstalkd/tree/v1.3/doc/protocol.txt?raw=true Pheanstalk 4In 2018 [Sam Mousa][3] took on the responsibility of maintaining Pheanstalk. Pheanstalk 4.0 drops support for older PHP versions. It contains the following changes (among other things): - Strict PHP type hinting - Value objects for Job IDs - Functions without side effects - Dropped support for persistent connections - Add support for multiple socket implementations (streams extension, socket extension, fsockopen) Dropping support persistent connectionsPersistent connections are a feature where a TCP connection is kept alive between different requests to reduce overhead
from TCP connection set up. When reusing TCP connections we must always guarantee that the application protocol, in this
case beanstalks' protocol is in a proper state. This is hard, and in some cases impossible; at the very least this means
we must do some tests which cause roundtrips.
Consider for example a connection that has just sent the command To prevent these kinds of issues the simplest solution is to not use persistent connections. Dropped connection handlingDepending on the socket implementation used we might not be able to enable TCP keepalive. If we do not have TCP keepalive
there is no way for us to detect dropped connections, the underlying OS may wait up to 15 minutes to decide that a TCP
connection where no packets are being sent is disconnected.
When using a socket implementation that supports read timeouts, like Example code for a job runner could look like this (this is real production code):
Here connection errors will cause the process to exit (and be restarted by a task manager). Functions with side effectsIn version 4 functions with side effects have been removed, functions like In this example, the tube changes meaning that the connection is now in a different state. This is not intuitive and forces any user of the connection to always switch / check the current tube. Another issue with this approach is that it is harder to deal with errors. If an exception occurs it is unclear whether we did or did not switch tube. Migration to v4A migration should in most cases be relatively simple:
- Change the constructor, either use the static constructor, use a DI container to construct the dependencies, or manually
instantiate them.
- Change instances of Installation with ComposerInstall pheanstalk as a dependency with composer:
Usage ExampleProducer
Consumer / Worker
Running the testsIf you have docker-compose installed running tests is as simple as:
If you don't then you manually need to set up a beanstalk server and run:
Contributors* Paul Annesley * Lachlan Donald * Joakim Bick * Vyacheslav * leprechaun * Peter McArthur * robbiehudson * Geoff Catlin * Steven Lewis * Lars Yencken * Josh Butts * Henry Smith * Javier Spagnoletti * Graham Campbell * Thomas Tourlourat * Matthieu Napoli * Christoph * James Hamilton * Hannes Van De Vreken * Yaniv Davidovitch * Sam Mousa * .. more? Let me know if you're missing. License© Paul Annesley Released under the The MIT License |