PHPackages                             cvo-technologies/cakephp-gearman - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. cvo-technologies/cakephp-gearman

ActiveCakephp-plugin[Queues &amp; Workers](/categories/queues)

cvo-technologies/cakephp-gearman
================================

A gearman plugin for CakePHP 3

2.0.1(9y ago)1243.5k↓33.3%6[2 issues](https://github.com/cvo-technologies/cakephp-gearman/issues)MITPHPPHP &gt;=5.5.9

Since Oct 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/cvo-technologies/cakephp-gearman)[ Packagist](https://packagist.org/packages/cvo-technologies/cakephp-gearman)[ Docs](https://github.com/cvo-technologies/cakephp-gearman)[ RSS](/packages/cvo-technologies-cakephp-gearman/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (8)Used By (0)

CakePHP Gearman plugin
======================

[](#cakephp-gearman-plugin)

[![Build Status](https://camo.githubusercontent.com/4ff1ec506bac8345e376b1f180f880f7333a743c28a6284410940bafa75a64be/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f43564f2d546563686e6f6c6f676965732f63616b657068702d676561726d616e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/CVO-Technologies/cakephp-gearman)[![Coverage Status](https://camo.githubusercontent.com/c3386d253711497be35bf1b44136429f525464ea8fef9f69c4eff4141d1ae153/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f43564f2d546563686e6f6c6f676965732f63616b657068702d676561726d616e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/cvo-technologies/cakephp-gearman)[![Total Downloads](https://camo.githubusercontent.com/2c269c1a798801624cf31bffa662e4bf35c018d58fef70ac4ea5d79d4bde1c45/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f43564f2d546563686e6f6c6f676965732f63616b657068702d676561726d616e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cvo-technologies/cakephp-gearman)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)

Gearman task offloading for CakePHP 3.

Requirements
------------

[](#requirements)

- PHP 5.5.9+
- CakePHP 3.2+
- [Gearman Job Server](http://gearman.org)
- [Gearman PHP extension](http://php.net/manual/en/book.gearman.php)

Why use this plugin?
--------------------

[](#why-use-this-plugin)

Use this plugin to drastically reduce page load times by offloading time consuming processes (like sending emails and resizing uploaded images) to a Gearman Job Server.

Installation
------------

[](#installation)

Install the plugin using [Composer](https://getcomposer.org):

```
composer require cvo-technologies/cakephp-gearman

```

Now load the plugin by either running this shell command:

```
bin/cake plugin load CvoTechnologies/Gearman --bootstrap

```

or by manually adding the following line to `config/bootstrap.php`:

```
Plugin::load('CvoTechnologies/Gearman', ['bootstrap' => true]);
```

Lastly, add a new `Gearman` configuration section to (most likely) `app.php`:

```
    'Gearman' => [
        'Servers' => [
            '127.0.0.1:4730'
        ],
        'Jobs' => [

        ]
    ]
```

### Optional: system verification

[](#optional-system-verification)

Before proceeding you might want to verify that the [Gearman Job Server](http://gearman.org//getting-started) is actually up and running on your local system.

On Ubuntu systems running `sudo netstat -peanut | grep gearman` should produce something similar to:

```
tcp      0     0 127.0.0.1:4730     0.0.0.0:*     LISTEN     0     9727     625/gearmand
tcp6     0     0 ::1:4730           :::*          LISTEN     0     9726     625/gearmand

```

Usage
-----

[](#usage)

Using this plugin comes down to:

1. Configuring your task(s)
2. Starting the `WorkerShell` on your local system
3. Offloading tasks from within your application code by using the `execute()`function found in the `JobAwareTrait`

To start the `WorkerShell` so it will listen for incoming tasks run the following command on your local system:

```
bin/cake worker

```

Built-in Tasks
--------------

[](#built-in-tasks)

### Email Task

[](#email-task)

This plugin comes with a built-in email task that allows you to start offloading emails using the worker instantly.

To enable the email task first add the following job to your Gearman configuration section:

```
    'Jobs' => [
        'className' => 'Email'
    ]
```

Then add the following worker configuration to your existing EmailTransporter configuration section (most likely found in `app.php`):

```
'worker' => [
    'className' => 'CvoTechnologies/Gearman.Worker',
    'transport' => 'default',
    'background' => true
]
```

Now all you need to do is use this EmailTransporter in your application when sending emails and it will automatically offload all email sending to the built-in task using the EmailTransporter defined in the `transport` key. E.g.

```
$email = new Email('default');
$res = $email->from(['you@example.com' => 'Your Site'])
    ->to('recipient@sexample.com')
    ->subject('Testing cakephp-gearman built-in EmailTask')
    ->send('Your message');
```

If things went well you should see the worker providing feedback on tasks being processed shown below:

[![Worker feedback](/docs/screenshot-worker-email.png)](/docs/screenshot-worker-email.png)

Creating your own tasks
-----------------------

[](#creating-your-own-tasks)

### 1. Create the Task

[](#1-create-the-task)

As an example we will create the following `SleepTask` that:

- will be used as a Gearman job
- must be created in `src/Shell/Task/SleepTask.php`
- must contain a `main()` function

```
