PHP code example of miknatr / net_gearman

1. Go to this page and download the library: Download miknatr/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/ */

    

miknatr / net_gearman example snippets




$client = new Net_Gearman_Client('localhost:7003');
$client->someBackgroundJob(array(
    'userid' => 5555,
    'action' => 'new-comment'
));



class Net_Gearman_Job_someBackgroundJob extends Net_Gearman_Job_Common
{
    public function run($args)
    {
        if (!isset($args['userid']) || !isset($args['action'])) {
            // Throw a Net_Gearman_Job_Exception to report back to the server that the job failed.
            throw new 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.
    }
}




$worker = new Net_Gearman_Worker('localhost:7003');
$worker->addAbility('someBackgroundJob');
$worker->beginWork();