{"id":20330546,"url":"https://github.com/mle86/php-wq","last_synced_at":"2025-03-04T12:37:45.505Z","repository":{"id":57018156,"uuid":"88792781","full_name":"mle86/php-wq","owner":"mle86","description":"A simple PHP library for work-queue and job handling.","archived":false,"fork":false,"pushed_at":"2022-05-24T09:38:07.000Z","size":281,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T05:46:27.448Z","etag":null,"topics":["php-library","php7","queued-jobs","work-queue","wq"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mle86.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-19T21:32:33.000Z","updated_at":"2022-05-24T11:56:54.000Z","dependencies_parsed_at":"2022-08-22T11:31:38.852Z","dependency_job_id":null,"html_url":"https://github.com/mle86/php-wq","commit_stats":null,"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mle86%2Fphp-wq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mle86%2Fphp-wq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mle86%2Fphp-wq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mle86%2Fphp-wq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mle86","download_url":"https://codeload.github.com/mle86/php-wq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241851233,"owners_count":20030961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php-library","php7","queued-jobs","work-queue","wq"],"created_at":"2024-11-14T20:16:38.327Z","updated_at":"2025-03-04T12:37:45.478Z","avatar_url":"https://github.com/mle86.png","language":"PHP","readme":"# WQ  (`mle86/wq`)\n\n[![Build Status](https://travis-ci.org/mle86/php-wq.svg?branch=master)](https://travis-ci.org/mle86/php-wq)\n[![Coverage Status](https://coveralls.io/repos/github/mle86/php-wq/badge.svg?branch=master)](https://coveralls.io/github/mle86/php-wq?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/mle86/wq/version)](https://packagist.org/packages/mle86/wq)\n[![PHP 8](https://img.shields.io/badge/php-8-8892BF.svg?style=flat)](https://php.net/)\n[![License](https://poser.pugx.org/mle86/wq/license)](https://packagist.org/packages/mle86/wq)\n\nThis package provides an easy way\nto put PHP tasks of any kind\ninto a work queue\nsuch as Beanstalkd or Redis\nto execute them at a later time.\n\nThis is\n**version 0.21.1**.\n\n\n# Installation and Dependencies\n\n```\n$ composer require mle86/wq\n```\n\nIt requires PHP 8.0+\nand has no other dependencies\n(apart from PHPUnit/Coveralls for development\n and the PSR-3 interfaces).\n\n## Adapter Implementations\n\nYou'll also want to install at least one other package\nwhich contains a `WorkServerAdapter` implementation,\nsuch as:\n\n* [mle86/wq-beanstalkd](https://github.com/mle86/php-wq-beanstalkd)\n    (Beanstalkd server adapter),\n* [mle86/wq-redis](https://github.com/mle86/php-wq-redis)\n    (Redis server adapter),\n* [mle86/wq-amqp](https://github.com/mle86/php-wq-amqp)\n    (RabbitMQ server adapter).\n\n\n# Basic Concepts\n\n- A *Job* is something which should be done exactly once.\nMaybe it's sending an e-mail,\nmaybe it's an external API call like a webhook,\nmaybe it's some slow clean-up process.\nIn any case, we're talking about a unit of work\nthat could be executed right away\nbut it would be better for the application's performance\nto put it in a *Work Queue* instead, so it can be done asynchronously.\n\n- A *Work Queue* is a list of jobs that should be executed at some other time.\nThey are stored in some kind of *Work Server*.\nOne work server well-known in the PHP world is [Beanstalkd](http://kr.github.io/beanstalkd/).\nIt can store any number of work queues, although it calls them “tubes”.\n\nDifferent work queues, or tubes, are commonly used to separate job types.\nFor example, the same work server might have\none “`mail`” queue for outgoing mails to be sent,\none “`cleanup`” queue for all kinds of clean-up jobs,\nand one “`webhook`” queue for outgoing web-hook calls.\n\nThis package provides some helpful classes\nto set up a simple work queue system.\n\n\n# Quick Start\n\nThis is our Job implementation.\nIt represents an e-mail that can be sent.\n\n```php\n\u003c?php\n\nuse mle86\\WQ\\Job\\AbstractJob;\n\nclass EMail extends AbstractJob\n{\n    protected $recipient;\n    protected $subject;\n    protected $message;\n    \n    public function __construct(string $recipient, string $subject, string $message)\n    {\n        $this-\u003erecipient = $recipient;\n        $this-\u003esubject   = $subject;\n        $this-\u003emessage   = $message;\n    }\n    \n    public function send()\n    {\n        if (mail($this-\u003erecipient, $this-\u003esubject, $this-\u003emessage)) {\n            // ok, has been sent!\n        } else {\n            throw new \\RuntimeException (\"mail() failed\");\n        }\n    }\n}\n```\n\n\nWe have some code using that e-mail class:\n\n```php\n\u003c?php\n\nuse mle86\\WQ\\WorkServerAdapter\\BeanstalkdWorkServer;\n\n$mailJob = new EMail(\"test@myproject.xyz\", \"Hello?\", \"This is a test mail.\");\n\n$workServer = BeanstalkdWorkServer::connect(\"localhost\");\n$workServer-\u003estoreJob(\"mail\", $mailJob);\n```\n\n\nAnd finally,\nwe have our background worker script\nwhich regularly checks the work server\nfor new e-mail jobs:\n\n```php\n\u003c?php\n\nuse mle86\\WQ\\WorkServerAdapter\\BeanstalkdWorkServer;\nuse mle86\\WQ\\WorkProcessor;\n\n$queue = \"mail\";\nprintf(\"%s worker %d starting.\\n\", $queue, getmypid());\n\n$processor  = new WorkProcessor(BeanstalkdWorkServer::connect(\"localhost\"));\n$fn_handler = function(EMail $mailJob) {\n    $mailJob-\u003esend();\n    // don't catch exceptions here, or the WorkProcessor won't see them.\n};\n\nwhile (true) {\n    try {\n        $processor-\u003eprocessNextJob($queue, $fn_handler);\n    } catch (\\Throwable $e) {\n        echo $e . \"\\n\";  // TODO: add some real logging here\n    }\n}\n```\n\n\n# Documentation\n\n1. [Implementing a Job class]\n1. [Execute or Queue]\n1. [Work the Queue]\n1. [Error Handling]\n1. [Usage Examples]\n\nClass reference:\n\n* [Job] interface\n    * [AbstractJob] base class\n    * [QueueEntry] wrapper class\n* [WorkServerAdapter] interface\n    * [AffixAdapter] wrapper class\n    * [BlackHoleWorkServer] dummy class\n* [WorkProcessor] class\n    * [SignalSafeWorkProcessor] class\n    * [JobResult] enum class\n    * [JobContext] dto class\n* [Exceptions](doc/Ref_Exceptions.md)\n\n\n[Job]: doc/Ref_Job_interface.md\n[AbstractJob]: doc/Ref_AbstractJob_base_class.md\n[WorkServerAdapter]: doc/Ref_WorkServerAdapter_interface.md\n[AffixAdapter]: doc/Ref_AffixAdapter_class.md\n[BlackHoleWorkServer]: doc/Ref_BlackHoleWorkServer_class.md\n[WorkProcessor]: doc/Ref_WorkProcessor_class.md\n[QueueEntry]: doc/Ref_QueueEntry_class.md\n[JobResult]: doc/Ref_JobResult_class.md\n[JobContext]: doc/Ref_JobContext_class.md\n\n[Implementing a Job class]: doc/Implementing_a_Job_class.md\n[Execute or Queue]: doc/Execute_or_Queue.md\n[Work the Queue]: doc/Work_the_Queue.md\n[Error Handling]: doc/Error_Handling.md\n[Usage Examples]: doc/Usage_Examples.md\n[SignalSafeWorkProcessor]: doc/Ref_SignalSafeWorkProcessor_class.md\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmle86%2Fphp-wq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmle86%2Fphp-wq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmle86%2Fphp-wq/lists"}