{"id":23546793,"url":"https://github.com/ph4r05/laravel-queue-database-ph4","last_synced_at":"2025-04-30T12:35:11.183Z","repository":{"id":42461595,"uuid":"115196581","full_name":"ph4r05/laravel-queue-database-ph4","owner":"ph4r05","description":"Laravel Database Queue with Optimistic locking ","archived":false,"fork":false,"pushed_at":"2024-05-15T20:23:39.000Z","size":67,"stargazers_count":50,"open_issues_count":10,"forks_count":16,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-16T23:03:17.935Z","etag":null,"topics":["database","database-queue","laravel","optimistic-locking","queue"],"latest_commit_sha":null,"homepage":"https://ph4r05.deadcode.me/blog/2017/12/23/laravel-queues-optimization.html","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/ph4r05.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-12-23T13:15:50.000Z","updated_at":"2022-07-05T13:51:05.000Z","dependencies_parsed_at":"2022-08-12T10:00:47.642Z","dependency_job_id":null,"html_url":"https://github.com/ph4r05/laravel-queue-database-ph4","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Flaravel-queue-database-ph4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Flaravel-queue-database-ph4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Flaravel-queue-database-ph4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Flaravel-queue-database-ph4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ph4r05","download_url":"https://codeload.github.com/ph4r05/laravel-queue-database-ph4/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235426493,"owners_count":18988420,"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":["database","database-queue","laravel","optimistic-locking","queue"],"created_at":"2024-12-26T09:06:46.411Z","updated_at":"2025-01-24T11:08:59.164Z","avatar_url":"https://github.com/ph4r05.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Database Queue driver for Laravel with optimistic locking\n=========================================================\n[![Latest Stable Version](https://poser.pugx.org/ph4r05/laravel-queue-database-ph4/v/stable?format=flat-square)](https://packagist.org/packages/ph4r05/laravel-queue-database-ph4)\n[![Build Status](https://img.shields.io/travis/ph4r05/laravel-queue-database-ph4.svg?style=flat-square)](https://travis-ci.org/ph4r05/laravel-queue-database-ph4)\n[![Total Downloads](https://poser.pugx.org/ph4r05/laravel-queue-database-ph4/downloads?format=flat-square)](https://packagist.org/packages/ph4r05/laravel-queue-database-ph4)\n[![StyleCI](https://styleci.io/repos/115196581/shield)](https://styleci.io/repos/115196581)\n[![License](https://poser.pugx.org/ph4r05/laravel-queue-database-ph4/license?format=flat-square)](https://packagist.org/packages/ph4r05/laravel-queue-database-ph4)\n\nLaravel database queue implementation using optimistic locking.\nIncreases concurrency, eliminates deadlocks. \n\n#### Installation\n\n1. Install this package via composer using:\n\n```\ncomposer require ph4r05/laravel-queue-database-ph4\n```\n\n2. Create job table\n\n```bash\nphp artisan queue_ph4:table\nphp artisan migrate\n```\n\n3. Queue configuration\n\n```php\n\u003c?php\n// config/queue.php\n\nreturn [\n    'database_ph4' =\u003e [\n        'driver' =\u003e 'database_ph4',\n        'table' =\u003e 'jobs_ph4',\n        'queue' =\u003e 'default',\n        'retry_after' =\u003e 4,\n        'num_workers' =\u003e 1,\n        'window_strategy' =\u003e 1,\n    ],\n];\n```\n\n- The `num_workers` should correspond to the number of workers processing jobs in the queue.\n- `window_strategy`. \n  - 0 means worker selects one available job for processing. \n  Smaller throughput, job ordering is preserved as with pessimistic locking.\n  - 1 means workers will select `num_workers` next available jobs and picks one at random.\n  Higher throughput with slight job reordering (for more info please refer to the [blog])\n\n\nTo use the optimistic locking you can now change your `.env`:\n\n```\nQUEUE_DRIVER=database_ph4\n```\n\n#### Usage\n\nOnce you completed the configuration you can use Laravel Queue API. If you used other queue drivers you do not need to change anything else. If you do not know how to use Queue API, please refer to the official Laravel documentation: http://laravel.com/docs/queues\n\n#### Testing\n\nRun the tests with:\n\n``` bash\nvendor/bin/phpunit\n```\n\n#### Blog post about optimistic locking\n\nhttps://ph4r05.deadcode.me/blog/2017/12/23/laravel-queues-optimization.html\n\nBenefits:\n\n - No need for explicit transactions. Single query auto-commit transactions are OK.\n - No DB level locking, thus no deadlocks. Works also with databases without deadlock detection (older MySQL).\n - Job executed exactly once (as opposed to pessimistic default DB locking)\n - High throughput.\n - Tested with MySQL, PostgreSQL, Sqlite.\n \nCons:\n - Job ordering can be slightly shifted with multiple workers (reordering 0-70 in 10 000 jobs)\n\n#### Contribution\n\nYou can contribute to this package by discovering bugs and opening issues. Please, add to which version of package you create pull request or issue. \n\n\n#### Donations\n\nThank you for all your support!\n\nMonero:\n```\n87iMuZKqgBZbxjvjJaieTqLBsW3VKtkiuRXL2arcr8eiL4eK8kFi4QbaXCXGgmNWYp5Linpd9pj5McFZ8SQevkenGuZWMCT\n```\n\nBitcoin:\n```\n17hzavLCXqavzmWEEjtX54VeCJVmbrHZQC\n```\n\n[blog]: https://ph4r05.deadcode.me/blog/2017/12/23/laravel-queues-optimization.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph4r05%2Flaravel-queue-database-ph4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fph4r05%2Flaravel-queue-database-ph4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph4r05%2Flaravel-queue-database-ph4/lists"}