PHP code example of frcho / crontask

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

    

frcho / crontask example snippets

bash


namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CronTasksDefaultCommand extends Command
{

    protected function configure()
    {

        $this->setName('crontasks:default')->setDescription('Creates the commands by default in database.');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {

        set_time_limit(0);
        ini_set('memory_limit', '-1');
        $container = $this->getApplication()->getKernel()->getContainer();
        $defaultCommands = array(
            array(
                "name" => "Example asset symlinking task",
                "interval" => 2, // Run once every 2 minutes,
                "range" => 'minutes',
                "commands" => 'assets:install --symlink web',
                "isHide" => false, /* "isHide == true, if you have enable view for this bundle, This command doesn't show in the view schedule task" */
                "enabled" => true
            ),
            array(
                "name" => "Example asset task",
                "interval" => 1, // Run once every hour
                "range" => 'hours',
                "commands" => 'cache:clear',
                "enabled" => false
            ),
        );

        $container->get('frcho.crontask_default')->setArrayCommands($defaultCommands);
        return 0;
    }
}