moonspot/gearman

PHP library for interfacing with Gearmand

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/moonspot/gearman

dev-main 2025-11-09 22:02 UTC

This package is auto-updated.

Last update: 2025-11-09 22:03:29 UTC


README

About

Moonspot\Gearman is a package for interfacing with Gearman. Gearman is a system to farm out work to other machines, dispatching function calls to machines that are better suited to do work, to do work in parallel, to load balance lots of function calls, or to call functions between languages.

Installation

$ composer require moonspot/gearman

Examples

Client

<?php

require __DIR__ . '/vendor/autoload.php';

use Moonspot\Gearman\Client;
use Moonspot\Gearman\Set;
use Moonspot\Gearman\Task;

$client = new Client('localhost');
$set = new Set();
$task = new Task('Reverse_String', 'foobar');
$task->attachCallback(
    function ($func, $handle, $result) {
        print_r($result);
    }
);
$set->addTask($task);
$client->runSet($set);

Job

<?php

namespace App\Gearman;

use Moonspot\Gearman\Job\Common;

class ReverseString extends Common
{
    public function run($workload)
    {
        return strrev($workload);
    }
}

Worker

For easiest use, use GearmanManager for running workers. See: https://github.com/brianlmoon/GearmanManager

<?php

require __DIR__ . '/vendor/autoload.php';

use Moonspot\Gearman\Worker;

$worker = new Worker('localhost');
$worker->addAbility('Reverse_String');
$worker->beginWork();

Functional Tests

To run the functional tests, docker is required. Run a gearmand in docker with a command like:

docker run -d -p 4730:4730 --rm \
    --name gearmand \
    artefactual/gearmand:latest

Once that is running, run the tests with the functional group flag.

./vendor/bin/phpunit --group=functional