shso / net_gearman
PHP 接口用于 Danga 的 Gearman
v1.1.0
2019-04-30 13:31 UTC
Requires (Dev)
- phpdocumentor/phpdocumentor: ^2.9
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2024-09-05 03:09:26 UTC
README
关于
Net_Gearman 是一个用于与 Danga 的 Gearman 进行接口的 PEAR 包。Gearman 是一个将工作分配给其他机器的系统,将函数调用调度到更适合执行工作的机器,以并行执行工作,负载均衡大量函数调用,或在不同语言之间调用函数。
Net_Gearman 曾在 Yahoo! 和 Digg 中投入生产,用于执行各种近实时处理工作。
此包 自 2011 年 2 月 23 日起没有更新。从现在起,我将负责维护。
安装
php composer.phar require shso/net_gearman
示例
客户端
<?php $client = new ShSo\Net\Gearman\Client('localhost:4730'); $client->someBackgroundJob([ 'userid' => 5555, 'action' => 'new-comment' ]);
工作
<?php namespace The\Job\Namespace; class someBackgroundJob extends ShSo\Net\Gearman\Job\Common { public function run($args) { if (!isset($args['userid']) || !isset($args['action'])) { throw new ShSo\Net\Gearman\Job\Exception('Invalid/Missing arguments'); } // Insert a record or something based on the $args return array(); // Results are returned to Gearman, except for // background jobs like this one. } }
工作者
<?php if (!defined('NET_GEARMAN_JOB_CLASS_PREFIX')) define('NET_GEARMAN_JOB_CLASS_PREFIX', "The\\Job\\Namespace\\"); $worker = new ShSo\Net\Gearman\Worker('localhost:4730'); $worker->addAbility('someBackgroundJob'); $worker->beginWork();