1. Go to this page and download the library: Download mkrmr/emphloyer 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/ */
mkrmr / emphloyer example snippets
use Emphloyer\AbstractJob
class NameEchoJob extends AbstractJob
{
public function setName(string $name) : void
{
$this->attributes['name'] = $name;
}
public function perform() : void
{
echo "Hi, my name is {$this->attributes['name']}.\n";
}
}
// $pipelineBackend defines the pipeline backend to use
$pipelineBackend = new \Emphloyer\Pdo\PipelineBackend('mysql:dbname=emphloyer_example;host=localhost', 'user', 'password');
// $employees determines the number of concurrent jobs, each job is forked off using pcntl_fork. Each entry is used, so if you specify duplicates that will simply add more employees for those types.
$employees = [
['exclude' => ['reports'], 'employees' => 2], // fork up to two processes for jobs of any type except 'reports'
['only' => ['reports', 'stuff'], 'employees' => 1], // fork up to one process for jobs of the types 'reports' and 'stuff'
['employees' => 4], // fork up to four processes for jobs of any type
];
$pipelineBackend = new \Emphloyer\Pdo\PipelineBackend('mysql:dbname=emphloyer_example;host=localhost', 'user', 'password');
$pipeline = new \Emphloyer\Pipeline($pipelineBackend);
$queuedJob = $pipeline->enqueue($job);
// $schedulerBackend defines the scheduler backend to use
$schedulerBackend = new \Emphloyer\Pdo\SchedulerBackend('mysql:dbname=emphloyer_example;host=localhost', 'user', 'password');
$schedulerBackend = new \Emphloyer\Pdo\SchedulerBackend('mysql:dbname=emphloyer_example;host=localhost', 'user', 'password');
$scheduler = new \Emphloyer\Scheduler($schedulerBackend);
// Arguments after the job follow the crontab syntax: minute, hour, day of month, month, day of week
$scheduler->schedule($job, 30, 12); // Schedules the job to be enqueued every day at 12:30
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.