How to create cron jobs on cakephp 4

Hi,

Thanks for reply.
I have created everything on my cPanel for run a cron job.
My cakePHP version is 4.x

I have a controller and I added a function there. I want to call this function using cron job.

I have created a file inside webroot named cron_despatcher.php
Here is the code:

<?php $_SERVER[ 'HTTP_HOST' ] = 'atgo.in'; // use only domain name here require dirname(__DIR__) . '/config/bootstrap.php'; use Cake\Network\Request; use Cake\Network\Response; use Cake\Routing\Router; use Cake\Routing\DispatcherFactory; if(PHP_SAPI == "cli" && $argc == 2) { $dispatcher = DispatcherFactory::create(); $request = new Request($argv[1]); $request = $request->addParams( Router::parse( $request->url, '' ) ); $dispatcher->dispatch( $request, new Response() ); } else { exit; } ?>

My controller code is here:

<?php namespace App\Controller; use App\Controller\AppController; class CornsController extends AppController{ public function initialize(): void { parent::initialize(); $this->loadModel("Corns"); $this->layout = false; } function addCorn() { $data = array(); $check_num = rand(); $data['check_num'] = $check_num; $corns = $this->Corns->newEmptyEntity(); $corn = $this->Corns->patchEntity($corns, $data); $this->Corns->save($corn); } } ?>

Cron Command:
/usr/local/bin/php /home/atgo/public_html/webroot/cron_dispatcher.php /Corns/addCorn

But not working.

Can you please check that if I did wrong anything!!!