{"id":21771126,"url":"https://github.com/initphp/queue","last_synced_at":"2025-03-21T06:22:11.593Z","repository":{"id":211689401,"uuid":"729754593","full_name":"InitPHP/Queue","owner":"InitPHP","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-10T08:49:48.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-26T03:13:44.160Z","etag":null,"topics":[],"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/InitPHP.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,"governance":null}},"created_at":"2023-12-10T08:48:34.000Z","updated_at":"2023-12-10T08:49:25.000Z","dependencies_parsed_at":"2023-12-10T09:20:15.083Z","dependency_job_id":"56f85f48-bf72-43b3-a999-08f208368bf8","html_url":"https://github.com/InitPHP/Queue","commit_stats":null,"previous_names":["initphp/queue"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FQueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FQueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FQueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FQueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InitPHP","download_url":"https://codeload.github.com/InitPHP/Queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244746787,"owners_count":20503264,"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":[],"created_at":"2024-11-26T14:15:09.775Z","updated_at":"2025-03-21T06:22:11.560Z","avatar_url":"https://github.com/InitPHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InitPHP Queue\r\n\r\nThis library offers performance and asynchrony by queuing your jobs to be done later.\r\n\r\n```\r\ncomposer require initphp/queue\r\n```\r\n\r\n## Create Job\r\n\r\nFirst, start by creating the business class. You can find a simple example below.\r\n\r\n```php\r\nrequire_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor/autoload.php';\r\n\r\nnamespace App\\Jobs;\r\n\r\nuse InitPHP\\Queue\\Job;\r\n\r\nclass MailJob extends Job\r\n{\r\n    protected string $channel = 'mailChannel';\r\n    \r\n    protected string $queue = 'mailQueue';\r\n    \r\n    public function handle(): bool\r\n    {\r\n        $payload = $this-\u003egetPayload();\r\n        try {\r\n            if (mail($payload['to'], $payload['subject'])) {\r\n                return true;\r\n            } else {\r\n                return false;;\r\n            }\r\n        } catch (\\Throwable $e) {\r\n            return false;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nUse the `push()` method to add jobs to the queue;\r\n\r\n```php\r\nrequire_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor/autoload.php';\r\n$adapter = new \\InitPHP\\Queue\\Adapters\\RabbitMQAdapter('127.0.0.1', 5267, 'guest', 'guest');\r\n\r\n$job = new App\\Jobs\\MailJob($adapter);\r\n\r\n// Add Queue Job\r\n$job-\u003epush([\r\n    'to'        =\u003e 'to@example.com',\r\n    'subject'   =\u003e 'Subject Mail',\r\n]);\r\n```\r\n\r\nWrite your code to handle the jobs in the queue.\r\n\r\n`consumer.php`\r\n\r\n```php\r\nrequire_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor/autoload.php';\r\n$adapter = new \\InitPHP\\Queue\\Adapters\\RabbitMQAdapter('127.0.0.1', 5267, 'guest', 'guest');\r\n\r\n$adapter-\u003ehandle('mailChannel', 'mailQueue');\r\n\r\n$adapter-\u003eclose();\r\n```\r\n\r\nTrigger your consumer code.\r\n\r\n```\r\nphp consumer.php\r\n```\r\n\r\n\r\n# Adapters\r\n- [x] [PDO (Database) Adapter](#pdo-adapter)\r\n- [x] [RabbitMQ Adapter](#rabbitmq-adapter)\r\n- [ ] Kafka Adapter\r\n\r\n## PDO Adapter\r\n\r\n- [x] PDO Extension\r\n\r\nTo initialize the PDO adapter, you need a PDO object and 2 tables.\r\n\r\n```php\r\n$pdo = new PDO('mysql:host=localhost;port=3307;dbname=queue_db', 'root', 'root');\r\n$adapter = new \\InitPHP\\Queue\\Adapters\\PDOAdapter($pdo, 'queue');\r\n```\r\n\r\nThe first of these tables is used for those waiting in line and the other for jobs that have errors. The table name into which the failed jobs fall is obtained by adding \"`_failed`\" as a suffix to the main table name. Accordingly, create your queue tables using the following SQL.\r\n\r\n```sql\r\nCREATE TABLE `queue` (\r\n        `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\r\n        `channel` VARCHAR(255) NOT NULL,\r\n        `queue` VARCHAR(255) NOT NULL,\r\n        `payload` TEXT NULL DEFAULT NULL,\r\n        `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\r\n        `updated_at` DATETIME NULL DEFAULT NULL,\r\n        `status` TINYINT(1) NOT NULL DEFAULT '0',\r\n        PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\r\nCREATE INDEX `channel_queue` ON `queue` (`channel`, `queue`);\r\n\r\nCREATE TABLE `queue_failed` (\r\n        `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\r\n        `queue_id` BIGINT UNSIGNED NOT NULL,\r\n        `channel` VARCHAR(255) NOT NULL,\r\n        `queue` VARCHAR(255) NOT NULL,\r\n        `payload` TEXT NULL DEFAULT NULL,\r\n        `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\r\n        `updated_at` DATETIME NULL DEFAULT NULL,\r\n        `status` TINYINT(1) NOT NULL DEFAULT '0',\r\n        PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\r\n```\r\n\r\n## RabbitMQ Adapter\r\n\r\n- [x] RabbitMQ Server\r\n- [x] \"`php-amqplib/php-amqplib`\" Library\r\n\r\n```\r\ncomposer require php-amqplib/php-amqplib\r\n```\r\n\r\n```php\r\n$adapter = new \\InitPHP\\Queue\\Adapters\\RabbitMQAdapter('127.0.0.1', 5267, 'guest', 'guest');\r\n```\r\n\r\n# Getting Involved\r\n\r\n\u003e All contributions to this project will be published under the MIT License. By submitting a pull request or filing a bug, issue, or feature request, you are agreeing to comply with this waiver of copyright interest.\r\n\r\nThere are two primary ways to help:\r\n\r\n- Using the issue tracker, and\r\n- Changing the code-base.\r\n\r\n## Using the issue tracker\r\n\r\nUse the issue tracker to suggest feature requests, report bugs, and ask questions. This is also a great way to connect with the developers of the project as well as others who are interested in this solution.\r\n\r\nUse the issue tracker to find ways to contribute. Find a bug or a feature, mention in the issue that you will take on that effort, then follow the Changing the code-base guidance below.\r\n\r\n## Changing the code-base\r\n\r\nGenerally speaking, you should fork this repository, make changes in your own fork, and then submit a pull request. All new code should have associated unit tests that validate implemented features and the presence or lack of defects. Additionally, the code should follow any stylistic and architectural guidelines prescribed by the project. In the absence of such guidelines, mimic the styles and patterns in the existing code-base.\r\n\r\n# Credits\r\n\r\n- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) \u003c\u003cinfo@muhammetsafak.com.tr\u003e\u003e\r\n\r\n# License\r\n\r\nCopyright \u0026copy; 2022 [MIT License](./LICENSE) \r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitphp%2Fqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finitphp%2Fqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitphp%2Fqueue/lists"}