PHP code example of cvo-technologies / cakephp-gearman

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

    

cvo-technologies / cakephp-gearman example snippets


Plugin::load('CvoTechnologies/Gearman', ['bootstrap' => true]);

    'Gearman' => [
        'Servers' => [
            '127.0.0.1:4730'
        ],
        'Jobs' => [

        ]
    ]

    'Jobs' => [
        'className' => 'Email'
    ]

'worker' => [
    'className' => 'CvoTechnologies/Gearman.Worker',
    'transport' => 'default',
    'background' => true
]

$email = new Email('default');
$res = $email->from(['[email protected]' => 'Your Site'])
    ->to('[email protected]')
    ->subject('Testing cakephp-gearman built-in EmailTask')
    ->send('Your message');


namespace CvoTechnologies\Gearman\Shell\Task;

use Cake\Console\Shell;

class SleepTask extends Shell
{

    public function main($workload, GearmanJob $job)
    {
        $job->sendStatus(0, 3);

        sleep($workload['timeout']);

        $job->sendStatus(1, 3);

        sleep($workload['timeout']);

        $job->sendStatus(2, 3);

        sleep($workload['timeout']);

        return array(
            'total_timeout' => $workload['timeout'] * 3
        );
    }
}