How do I create a cronjob in symfony3 for a given controller? I need it to run every 30 minutes.
controller action path is '/update'
<?php
namespace AppBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Finder\Finder;
class UpdateCommand extends Command
{
protected function configure()
{
$this
->setName('app:update:products')
->setDescription('Update de Productos')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln([
'Inicio de Actualización',
'============>',
'',
]);
$path = get('kernel')->getRootDir() . '/../web';
$finder = new Finder();
$finder->files()->in($path);
$finder->name('productos.txt');
foreach ($finder as $file) {
$contents = $file->getContents();
$arrayContents = str_getcsv($contents,'
');
//var_dump($arrayContents);
foreach ($arrayContents as $dato){
$datos= str_getcsv($dato,' ');
var_dump($datos);
}
}
$client = new SoapClient('https://example_wsdl.php?v=01.02');
$synchro = $client->__soapCall(
'Sincronizacion',
[[
'param1'=> xxxx,
'param2'=>'xxxx',
'param3' => 'xxxx'
]]
);
var_export($sinchro);
}
}
?>
Here I leave you a link to the crontask documentation, even so I will explain it to you a little in a rough way.
To configure a cronjob / crontask you will need to create a new directory at the Controller / Entity level, and create a Command document there and like the others in your case it would be ClientCommand
I enclose an example of how the ClientCommand file should go, even so I recommend that you read the documentation for more information
This would update it every 30 min, you have to execute that command, if you put the
/
in front of 30 (minutes) it will execute it every 30 minutes, if you don't put it it will execute it at 30 minutes once