[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8511":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":16,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":17,"rankGlobal":10,"rankLanguage":10,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":19,"hasPages":19,"topics":21,"createdAt":10,"pushedAt":10,"updatedAt":22,"readmeContent":23,"aiSummary":24,"trendingCount":16,"starSnapshotCount":16,"syncStatus":25,"lastSyncTime":26,"discoverSource":27},8511,"php-resque","chrisboulton\u002Fphp-resque","chrisboulton","PHP port of resque (Workers and Queueing)","",null,"PHP",3415,742,214,77,0,60.61,"MIT License",false,"master",[],"2026-06-12 04:00:40","php-resque: PHP Resque Worker (and Enqueue) [![Build Status](https:\u002F\u002Fsecure.travis-ci.org\u002Fchrisboulton\u002Fphp-resque.png)](http:\u002F\u002Ftravis-ci.org\u002Fchrisboulton\u002Fphp-resque)\n===========================================\n\nResque is a Redis-backed library for creating background jobs, placing\nthose jobs on one or more queues, and processing them later.\n\n## Background ##\n\nResque was pioneered and is developed by the fine folks at GitHub (yes,\nI am a kiss-ass), and written in Ruby. What you're seeing here is an\nalmost direct port of the Resque worker and enqueue system to PHP.\n\nFor more information on Resque, visit the official GitHub project:\n \u003Chttps:\u002F\u002Fgithub.com\u002Fresque\u002Fresque>\n\nFor further information, see the launch post on the GitHub blog:\n \u003Chttp:\u002F\u002Fgithub.com\u002Fblog\u002F542-introducing-resque>\n\nThe PHP port does NOT include its own web interface for viewing queue\nstats, as the data is stored in the exact same expected format as the\nRuby version of Resque.\n\nThe PHP port provides much the same features as the Ruby version:\n\n* Workers can be distributed between multiple machines\n* Includes support for priorities (queues)\n* Resilient to memory leaks (forking)\n* Expects failure\n\nIt also supports the following additional features:\n\n* Has the ability to track the status of jobs\n* Will mark a job as failed, if a forked child running a job does\nnot exit with a status code as 0\n* Has built in support for `setUp` and `tearDown` methods, called\npre and post jobs\n\n## Requirements ##\n\n* PHP 5.3+\n* Redis 2.2+\n* Optional but Recommended: Composer\n\n## Getting Started ##\n\nThe easiest way to work with php-resque is when it's installed as a\nComposer package inside your project. Composer isn't strictly\nrequired, but makes life a lot easier.\n\nIf you're not familiar with Composer, please see \u003Chttp:\u002F\u002Fgetcomposer.org\u002F>.\n\n1. Add php-resque to your application's composer.json.\n\n```json\n{\n    \"require\": {\n        \"chrisboulton\u002Fphp-resque\": \"1.2.x\"\n    }\n}\n```\n\n2. Run `composer install`.\n\n3. If you haven't already, add the Composer autoload to your project's\n   initialization file. (example)\n\n```sh\nrequire 'vendor\u002Fautoload.php';\n```\n\n## Jobs ##\n\n### Queueing Jobs ###\n\nJobs are queued as follows:\n\n```php\n\u002F\u002F Required if redis is located elsewhere\nResque::setBackend('localhost:6379');\n\n$args = array(\n        'name' => 'Chris'\n        );\nResque::enqueue('default', 'My_Job', $args);\n```\n\n### Defining Jobs ###\n\nEach job should be in its own class, and include a `perform` method.\n\n```php\nclass My_Job\n{\n    public function perform()\n    {\n        \u002F\u002F Work work work\n        echo $this->args['name'];\n    }\n}\n```\n\nWhen the job is run, the class will be instantiated and any arguments\nwill be set as an array on the instantiated object, and are accessible\nvia `$this->args`.\n\nAny exception thrown by a job will result in the job failing - be\ncareful here and make sure you handle the exceptions that shouldn't\nresult in a job failing.\n\nJobs can also have `setUp` and `tearDown` methods. If a `setUp` method\nis defined, it will be called before the `perform` method is run.\nThe `tearDown` method, if defined, will be called after the job finishes.\n\n\n```php\nclass My_Job\n{\n    public function setUp()\n    {\n        \u002F\u002F ... Set up environment for this job\n    }\n\n    public function perform()\n    {\n        \u002F\u002F .. Run job\n    }\n\n    public function tearDown()\n    {\n        \u002F\u002F ... Remove environment for this job\n    }\n}\n```\n\n### Dequeueing Jobs ###\n\nThis method can be used to conveniently remove a job from a queue.\n\n```php\n\u002F\u002F Removes job class 'My_Job' of queue 'default'\nResque::dequeue('default', ['My_Job']);\n\n\u002F\u002F Removes job class 'My_Job' with Job ID '087df5819a790ac666c9608e2234b21e' of queue 'default'\nResque::dequeue('default', ['My_Job' => '087df5819a790ac666c9608e2234b21e']);\n\n\u002F\u002F Removes job class 'My_Job' with arguments of queue 'default'\nResque::dequeue('default', ['My_Job' => array('foo' => 1, 'bar' => 2)]);\n\n\u002F\u002F Removes multiple jobs\nResque::dequeue('default', ['My_Job', 'My_Job2']);\n```\n\nIf no jobs are given, this method will dequeue all jobs matching the provided queue.\n\n```php\n\u002F\u002F Removes all jobs of queue 'default'\nResque::dequeue('default');\n```\n\n### Tracking Job Statuses ###\n\nphp-resque has the ability to perform basic status tracking of a queued\njob. The status information will allow you to check if a job is in the\nqueue, is currently being run, has finished, or has failed.\n\nTo track the status of a job, pass `true` as the fourth argument to\n`Resque::enqueue`. A token used for tracking the job status will be\nreturned:\n\n```php\n$token = Resque::enqueue('default', 'My_Job', $args, true);\necho $token;\n```\n\nTo fetch the status of a job:\n\n```php\n$status = new Resque_Job_Status($token);\necho $status->get(); \u002F\u002F Outputs the status\n```\n\nJob statuses are defined as constants in the `Resque_Job_Status` class.\nValid statuses include:\n\n* `Resque_Job_Status::STATUS_WAITING` - Job is still queued\n* `Resque_Job_Status::STATUS_RUNNING` - Job is currently running\n* `Resque_Job_Status::STATUS_FAILED` - Job has failed\n* `Resque_Job_Status::STATUS_COMPLETE` - Job is complete\n* `false` - Failed to fetch the status - is the token valid?\n\nStatuses are available for up to 24 hours after a job has completed\nor failed, and are then automatically expired. A status can also\nforcefully be expired by calling the `stop()` method on a status\nclass.\n\n## Workers ##\n\nWorkers work in the exact same way as the Ruby workers. For complete\ndocumentation on workers, see the original documentation.\n\nA basic \"up-and-running\" `bin\u002Fresque` file is included that sets up a\nrunning worker environment. (`vendor\u002Fbin\u002Fresque` when installed\nvia Composer)\n\nThe exception to the similarities with the Ruby version of resque is\nhow a worker is initially setup. To work under all environments,\nnot having a single environment such as with Ruby, the PHP port makes\n*no* assumptions about your setup.\n\nTo start a worker, it's very similar to the Ruby version:\n\n```sh\n$ QUEUE=file_serve php bin\u002Fresque\n```\n\nIt's your responsibility to tell the worker which file to include to get\nyour application underway. You do so by setting the `APP_INCLUDE` environment\nvariable:\n\n```sh\n$ QUEUE=file_serve APP_INCLUDE=..\u002Fapplication\u002Finit.php php bin\u002Fresque\n```\n\n*Pro tip: Using Composer? More than likely, you don't need to worry about\n`APP_INCLUDE`, because hopefully Composer is responsible for autoloading\nyour application too!*\n\nGetting your application underway also includes telling the worker your job\nclasses, by means of either an autoloader or including them.\n\nAlternately, you can always `include('bin\u002Fresque')` from your application and\nskip setting `APP_INCLUDE` altogether.  Just be sure the various environment\nvariables are set (`setenv`) before you do.\n\n### Logging ###\n\nThe port supports the same environment variables for logging to STDOUT.\nSetting `VERBOSE` will print basic debugging information and `VVERBOSE`\nwill print detailed information.\n\n```sh\n$ VERBOSE=1 QUEUE=file_serve bin\u002Fresque\n$ VVERBOSE=1 QUEUE=file_serve bin\u002Fresque\n```\n\n### Priorities and Queue Lists ###\n\nSimilarly, priority and queue list functionality works exactly\nthe same as the Ruby workers. Multiple queues should be separated with\na comma, and the order that they're supplied in is the order that they're\nchecked in.\n\nAs per the original example:\n\n```sh\n$ QUEUE=file_serve,warm_cache bin\u002Fresque\n```\n\nThe `file_serve` queue will always be checked for new jobs on each\niteration before the `warm_cache` queue is checked.\n\n### Running All Queues ###\n\nAll queues are supported in the same manner and processed in alphabetical\norder:\n\n```sh\n$ QUEUE='*' bin\u002Fresque\n```\n\n### Running Multiple Workers ###\n\nMultiple workers can be launched simultaneously by supplying the `COUNT`\nenvironment variable:\n\n```sh\n$ COUNT=5 bin\u002Fresque\n```\n\nBe aware, however, that each worker is its own fork, and the original process\nwill shut down as soon as it has spawned `COUNT` forks.  If you need to keep\ntrack of your workers using an external application such as `monit`, you'll\nneed to work around this limitation.\n\n### Custom prefix ###\n\nWhen you have multiple apps using the same Redis database it is better to\nuse a custom prefix to separate the Resque data:\n\n```sh\n$ PREFIX=my-app-name bin\u002Fresque\n```\n\n### Forking ###\n\nSimilarly to the Ruby versions, supported platforms will immediately\nfork after picking up a job. The forked child will exit as soon as\nthe job finishes.\n\nThe difference with php-resque is that if a forked child does not\nexit nicely (PHP error or such), php-resque will automatically fail\nthe job.\n\n### Signals ###\n\nSignals also work on supported platforms exactly as in the Ruby\nversion of Resque:\n\n* `QUIT` - Wait for job to finish processing then exit\n* `TERM` \u002F `INT` - Immediately kill job then exit\n* `USR1` - Immediately kill job but don't exit\n* `USR2` - Pause worker, no new jobs will be processed\n* `CONT` - Resume worker.\n\n### Process Titles\u002FStatuses ###\n\nThe Ruby version of Resque has a nifty feature whereby the process\ntitle of the worker is updated to indicate what the worker is doing,\nand any forked children also set their process title with the job\nbeing run. This helps identify running processes on the server and\ntheir resque status.\n\n**PHP does not have this functionality by default until 5.5.**\n\nA PECL module (\u003Chttp:\u002F\u002Fpecl.php.net\u002Fpackage\u002Fproctitle>) exists that\nadds this functionality to PHP before 5.5, so if you'd like process\ntitles updated, install the PECL module as well. php-resque will\nautomatically detect and use it.\n\n## Event\u002FHook System ##\n\nphp-resque has a basic event system that can be used by your application\nto customize how some of the php-resque internals behave.\n\nYou listen in on events (as listed below) by registering with `Resque_Event`\nand supplying a callback that you would like triggered when the event is\nraised:\n\n```sh\nResque_Event::listen('eventName', [callback]);\n```\n\n`[callback]` may be anything in PHP that is callable by `call_user_func_array`:\n\n* A string with the name of a function\n* An array containing an object and method to call\n* An array containing an object and a static method to call\n* A closure (PHP 5.3+)\n\nEvents may pass arguments (documented below), so your callback should accept\nthese arguments.\n\nYou can stop listening to an event by calling `Resque_Event::stopListening`\nwith the same arguments supplied to `Resque_Event::listen`.\n\nIt is up to your application to register event listeners. When enqueuing events\nin your application, it should be as easy as making sure php-resque is loaded\nand calling `Resque_Event::listen`.\n\nWhen running workers, if you run workers via the default `bin\u002Fresque` script,\nyour `APP_INCLUDE` script should initialize and register any listeners required\nfor operation. If you have rolled your own worker manager, then it is again your\nresponsibility to register listeners.\n\nA sample plugin is included in the `extras` directory.\n\n### Events ###\n\n#### beforeFirstFork ####\n\nCalled once, as a worker initializes. Argument passed is the instance of `Resque_Worker`\nthat was just initialized.\n\n#### beforeFork ####\n\nCalled before php-resque forks to run a job. Argument passed contains the instance of\n`Resque_Job` for the job about to be run.\n\n`beforeFork` is triggered in the **parent** process. Any changes made will be permanent\nfor as long as the **worker** lives.\n\n#### afterFork ####\n\nCalled after php-resque forks to run a job (but before the job is run). Argument\npassed contains the instance of `Resque_Job` for the job about to be run.\n\n`afterFork` is triggered in the **child** process after forking out to complete a job. Any\nchanges made will only live as long as the **job** is being processed.\n\n#### beforePerform ####\n\nCalled before the `setUp` and `perform` methods on a job are run. Argument passed\ncontains the instance of `Resque_Job` for the job about to be run.\n\nYou can prevent execution of the job by throwing an exception of `Resque_Job_DontPerform`.\nAny other exceptions thrown will be treated as if they were thrown in a job, causing the\njob to fail.\n\n#### afterPerform ####\n\nCalled after the `perform` and `tearDown` methods on a job are run. Argument passed\ncontains the instance of `Resque_Job` that was just run.\n\nAny exceptions thrown will be treated as if they were thrown in a job, causing the job\nto be marked as having failed.\n\n#### onFailure ####\n\nCalled whenever a job fails. Arguments passed (in this order) include:\n\n* Exception - The exception that was thrown when the job failed\n* Resque_Job - The job that failed\n\n#### beforeEnqueue ####\n\nCalled immediately before a job is enqueued using the `Resque::enqueue` method.\nArguments passed (in this order) include:\n\n* Class - string containing the name of the job to be enqueued\n* Arguments - array of arguments for the job\n* Queue - string containing the name of the queue the job is to be enqueued in\n* ID - string containing the token of the job to be enqueued\n\nYou can prevent enqueing of the job by throwing an exception of `Resque_Job_DontCreate`.\n\n#### afterEnqueue ####\n\nCalled after a job has been queued using the `Resque::enqueue` method. Arguments passed\n(in this order) include:\n\n* Class - string containing the name of scheduled job\n* Arguments - array of arguments supplied to the job\n* Queue - string containing the name of the queue the job was added to\n* ID - string containing the new token of the enqueued job\n\n## Step-By-Step ##\n\nFor a more in-depth look at what php-resque does under the hood (without \nneeding to directly examine the code), have a look at `HOWITWORKS.md`.\n\n## Contributors ##\n\n### Project Lead ###\n\n* @chrisboulton\n\n### Others ###\n\n* @acinader\n* @ajbonner\n* @andrewjshults\n* @atorres757\n* @benjisg\n* @cballou\n* @chaitanyakuber\n* @charly22\n* @CyrilMazur\n* @d11wtq\n* @danhunsaker\n* @dceballos\n* @ebernhardson\n* @hlegius\n* @hobodave\n* @humancopy\n* @iskandar\n* @JesseObrien\n* @jjfrey\n* @jmathai\n* @joshhawthorne\n* @KevBurnsJr\n* @lboynton\n* @maetl\n* @matteosister\n* @MattHeath\n* @mickhrmweb\n* @Olden\n* @patrickbajao\n* @pedroarnal\n* @ptrofimov\n* @rajibahmed\n* @richardkmiller\n* @Rockstar04\n* @ruudk\n* @salimane\n* @scragg0x\n* @scraton\n* @thedotedge\n* @tonypiper\n* @trimbletodd\n* @warezthebeef\n","php-resque 是一个基于 Redis 的 PHP 库，用于创建后台任务、将这些任务放入一个或多个队列，并在之后进行处理。其核心功能包括支持多机器分布式的 worker、优先级队列管理以及通过 fork 机制防止内存泄漏等。此外，它还提供了任务状态跟踪、失败标记以及 `setUp` 和 `tearDown` 方法的支持，以增强任务执行前后的灵活性与可控性。此项目适用于需要异步处理耗时操作的场景，如发送邮件、图片处理等后台任务处理需求。由于依赖于 Redis 和 PHP 5.3+ 环境，建议结合 Composer 进行安装和管理。",2,"2026-06-11 03:18:23","top_language"]