PHP code example of devcreel / command-lockable-trait

1. Go to this page and download the library: Download devcreel/command-lockable-trait 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/ */

    

devcreel / command-lockable-trait example snippets




namespace TestBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use DevCreel\Command\LockableTrait;

class TestCommand extends ContainerAwareCommand
{
    use LockableTrait;
    
    //count of threads
    private $threadsCount = 5;
    
    protected function configure()
    {
        $this->setName('test:run');
    }
    
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        //check for free thread
        if (!$this->lock()) {
            $output->writeln('[' . $this->getName() . '] is already running in another process.');
            return 0;
        }
        
        //your code...
        
        //release thread
        $this->release();
    }
    
}