PHP code example of lsr / scheduler

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

    

lsr / scheduler example snippets




declare(strict_types=1);

namespace App\Tasks;

use Lsr\Scheduler\SchedulerJobContext;
use Lsr\Scheduler\SchedulerJobInterface;

final readonly class DeleteExpiredSessionsJob implements SchedulerJobInterface
{
	public function run(SchedulerJobContext $context): void
	{
		// Delete expired sessions or dispatch asynchronous work.
	}
}



declare(strict_types=1);

namespace App\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Scheduler\Attribute\AsCronTask;
use Symfony\Component\Scheduler\Attribute\AsPeriodicTask;

#[AsCommand(name: 'sessions:delete-expired')]
#[AsCronTask('0 * * * *', timezone: 'Europe/Prague')]
#[AsPeriodicTask('15 minutes', arguments: ['--batch-size' => 500])]
final class DeleteExpiredSessionsCommand extends Command
{
	// Normal Symfony Console command implementation.
}

#[AsCronTask('0 3 * * *', arguments: ['tenant' => 'main', '--force' => true])]
#[AsCronTask('0 4 * * *', arguments: 'archive --limit=500')]
shell
php bin/console debug:scheduler