PHP code example of incapption / load-balanced-cron-task
1. Go to this page and download the library: Download incapption/load-balanced-cron-task 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/ */
incapption / load-balanced-cron-task example snippets
use Incapption\LoadBalancedCronTask\Abstracts\CronTaskAbstract;
use Incapption\LoadBalancedCronTask\LoadBalancedCronTask;
use Incapption\LoadBalancedCronTask\Exceptions\LoadBalancedCronTaskException;
return file_put_contents('test.html', 'awesome! it works! '.date('Y-m-d H:i:s', time()));
}
}
try {
$response = (new LoadBalancedCronTask())
->mysql($_ENV['MYSQL_HOST'], $_ENV['MYSQL_USER'], $_ENV['MYSQL_PASSWORD'], $_ENV['MYSQL_DATABASE'])
->setWorkerName('Node 1')
->task((new TestCronTask()))
->loadBalanced()
->everyMinute()
->run();
} catch (LoadBalancedCronTaskException $e) {
exit($e->getMessage());
}
# Example for a distributed load balanced cron task
$response = (new LoadBalancedCronTask())
->mysql($_ENV['MYSQL_HOST'], $_ENV['MYSQL_USER'], $_ENV['MYSQL_PASSWORD'], $_ENV['MYSQL_DATABASE'])
->setWorkerName('Node 1')
->task((new TestCronTask()))
->loadBalanced()
->everyMinute()
->run();
# Example for a local cron task
$response = (new LoadBalancedCronTask())
->task((new TestCronTask()))
->local()
->everyMinute()
->run();