PHP code example of mluex / endless-cron-command

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

    

mluex / endless-cron-command example snippets


namespace Acme\DemoBundle\Command;

use Mluex\EndlessCronCommand\EndlessCronCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MinimalDemoCommand extends EndlessCronCommand
{
    // This is just a normal Command::configure() method
    protected function configure(): void
    {
        $this->setName('acme:minimaldemo')
            ->setDescription('An EndlessCronCommand implementation example');
    }

    // Method will be called in an endless loop
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        // Do some work
        file_put_contents('/tmp/acme-timestamp.txt', time());
    }
}

namespace Acme\DemoBundle\Command;

use Mluex\EndlessCronCommand\EndlessCronCommand;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MinimalDemoCommand extends EndlessCronCommand
{
    public function __construct(
        private readonly LoggerInterface $logger,
        string $name = null
    ) {
        parent::__construct($name);
    }

    // This is just a normal Command::configure() method
    protected function configure(): void
    {
        $this->setName('acme:minimaldemo')
            ->setDescription('An EndlessCronCommand implementation example');
    }

    // Method will be called in an endless loop
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        // Do some work
        file_put_contents('/tmp/acme-timestamp.txt', time());
        
        // Clear FingersCrossed Log Handlers
        $this->clearFingersCrossedLogHandlers($this->logger);
    }
}