PHP code example of shso / net_gearman

1. Go to this page and download the library: Download shso/net_gearman library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shso / net_gearman example snippets




$client = new ShSo\Net\Gearman\Client('localhost:4730');
$client->someBackgroundJob([
    'userid' => 5555,
    'action' => 'new-comment'
]);



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.
    }
}



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();
sh
php composer.phar