Created custom commands to import the data(Not a shell comand), I want to execute the command from the controller, Let me know how can I execute the command in cakephp4 controller.
I tried to use
use Cake\Console\CommandRunner;
$command = new CommandRunner();
$command->run([‘import_users’]);
But I am getting below error while creating object**($command = new CommandRunner();)**
“Too few arguments to function Cake\Console\CommandRunner::__construct()”
If the comand spends more time than the maximum request time (usually 30-40 seconds), the executing commands is killed when reaches that limit.
I suggest creating a process with that command, so that the request finishes quickly. The command should be responsible to update process progress somewhere (like having a tasks model and update percent there)
Create a new process like this: (launch ExampleCommand)
If you’re getting the exact same error as the OP was, then my reply should be helpful. If you’re getting some other issue, then of course it would not be.
Thankyou I was just about to make a mess of trying to shoe horn CommandRunner into a controller. I greatly appreciate your contributions of knowledge Kevin.