Download the PHP package demi/php-gearman without Composer
On this page you can find all versions of the php package demi/php-gearman. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-gearman
php-gearman-job-server
Gearman job server workers helper
Installation
-
Run:
- Install gearman job server as PHP-extension: http://gearman.org/getting-started/#gearman_php_extension
-
Install supervisor:
- (optional) Install Gearman GUI: http://gaspaio.github.io/gearmanui
Configuration
Yii1/Yii2:
supervisor.php at you common config dir:
Gearman component configuration
Yii2
/common/config/main.php:
/console/config/main.php:
Yii1
/protected/config/main.php:
/protected/config/console.php:
Laravel:
Add service provider to /config/app.php:
Publish /config/gearman.php
Usage
Running workers:
Gearman workers - it is simple looped console commands
Yii2:
Create new console controller
/console/controllers/WorkersController.php:
`
Yii1:
Create new console command
/protected/commands/WorkersCommand.php:
`
Laravel:
Create new console command
/app/Console/Commands/CropImage.php:
Update /app/Console/Kernel.php:<br /> Add to
protected $commands`:
Change supervisor config set and restart supervisor:
Yii2: `
Yii1: `
Laravel: `
Examples
Yii2:
At any place:
Yii1:
At any place:
Laravel:
At any place:
use Gearman;
// synchronous
$result = Gearman::doNormal('crop_image', ['image_path' => '/var/www/image.jpg']);
var_dump(Gearman::deserializeWorkload($result)); // ['status' => 'success', 'foo' => 'bar']
$result = Gearman::doNormal('crop_image');
var_dump(Gearman::deserializeWorkload($result)); // ['status' => 'error', 'message' => 'No image']
// asynchronous
$result = Gearman::doBackground('crop_image', ['image_path' => '/var/www/image.jpg']);
var_dump($result); // job handle file descriptior
$result = Gearman::doBackground('crop_image');
var_dump($result); // job handle file descriptior
// Variants:
// doLow(), doNormal(), doHigh(),
// doLowBackground(), doBackground(), doHighBackground(),