PHP code example of jayesbe / php-process-executive

1. Go to this page and download the library: Download jayesbe/php-process-executive 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/ */

    

jayesbe / php-process-executive example snippets


namespace FooBar\AppBundle\Command;

// use Symfony\Component\Console\Command\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
use FooBar\UserBundle\Entity\User;

use ProcessExecutive\Executive;
use ProcessExecutive\ExecutiveControl;

/**
 * GenerateUsers command for testing purposes. 
 * 
 * Will generate random users
 *
 * You could also extend from Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
 * to get access to the container via $this->getContainer().
 *
 * @author Jayesbe
 */
class GenerateUsersCommand extends ContainerAwareCommand implements ExecutiveControl
{
    const MAX_USERS = 5000000;
    
    private 
    
    $userSize,
    
    $totalGenerated,
    
    $output;
    
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this->userSize = 0;
        $this->totalGenerated = 0;
        
        $this
            ->setName('foobar:generate:users')
            ->setDescription('Populate database with random users.')
            ->addArgument('size', InputArgument::OPTIONAL, 'Number of Users to generate', self::MAX_USERS)
            ->setHelp(<<<EOF
The <info>%command.name%</info> will populate the database with randomly generated users.
                    
The optional argument specifies the size of the population to generate (up to a maximum of 5 million):
        
<info>php %command.full_name%</info> 5000000
EOF
            );               
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;

        $this->userSize = intval($input->getArgument('size'));
        if ($this->userSize > self::MAX_USERS) {
            $output->writeln("Attempted to populate with ".$this->userSize.' users. Max allowed '.self::MAX_USERS);
            return;
        }
        $output->writeln("Attempting to populate with ".$this->userSize.' users...');
        
        // we call these to make sure they are created in the parent
        $doctrine = $this->getContainer()->get('doctrine');
        $em = $doctrine->getManager();       
        
        // we need to create our Executive here
        $processor = new Executive($this);
        
        // your queue can be anything.
        $queue = array(0 => $this->userSize);
        
        // execute our queue
        $processor->execute($queue);
                
        $output->writeln(sprintf('Population Created: <comment>%s</comment> users!', $this->totalGenerated));
    }
    
    public function closeResources()
    {
        // close all db connections and memcache connections.
        // anything that