PHP code example of yalesov / zf2-cron

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

    

yalesov / zf2-cron example snippets


use Yalesov\Cron\Service\Cron;
Cron::register(
  'foo',
  '*/15 * * * *',
  'Foo::runCron',
  array('bar', 'baz')
);

public static function register($code, $frequency, $callback, array $args = array())

// $em instance of EntityManager
$errorJobs = $em->getRepository('Yalesov\Cron\Entity\Job')->findBy(array(
  'code'   => 'foo',
  'status' => \Yalesov\Cron\Repository\Job::STATUS_ERROR,
));
foreach ($errorJobs as $job) {
  echo sprintf(
    "cron job, code %s, executed at %s with error \n %s \n\n",
    $job->getCode(), // will always be 'foo' in this example
    $job->getExecuteTime()->format('r'),
    $job->getErrorMsg()
  );
}
sh
$ php public/index.php cron