PHP code example of mftsoft / schedule

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

    

mftsoft / schedule example snippets




namespace App\Jobs;

use Schedule\Core\AbstractTask;

class LimparLogsTask extends AbstractTask
{
    /**
     * Define um nome único para a tarefa.
     */
    public function getName(): string
    {
        return 'limpar_logs_antigos';
    }

    /**
     * Define a expressão Cron de quando a tarefa deve rodar.
     * Exemplo: Todo dia à meia-noite
     */
    public function getExpression(): string
    {
        return '0 0 * * *';
    }

    /**
     * A lógica da sua regra de negócio.
     */
    public function handle(): void
    {
        // ... Sua lógica de limpeza aqui
    }
}



chedule\TaskFactory;
use App\Jobs\LimparLogsTask;

// (Opcional) Configura caminhos customizados para os diretórios tmp e logs
TaskFactory::setConfig('/caminho/absoluto/tmp', '/caminho/absoluto/logs');

// Passe as instâncias das tarefas (ou o nome da classe em string)
TaskFactory::run([
    new LimparLogsTask(),
]);



use Schedule\TaskFactory;

class SchedulerService
{
    /**
     * Ponto de entrada chamado via CLI (cmd.php)
     */
    public static function run($param): void
    {
        // (Opcional) Configura caminhos customizados para logs e tmp
        // TaskFactory::setConfig(__DIR__.'/../../../tmp', __DIR__.'/../../../logs');

        // Dispara o Scheduler registrando as suas tarefas
        TaskFactory::run([
            new \App\Service\Task\SelectNewsTask(),
            new \App\Service\Chatwoot\SearchTask(),
        ]);
    }
}
bash
* * * * * php /caminho/do/projeto/cmd.php "class=SchedulerService&method=run" >> /dev/null 2>&1