You can write a PHP script to run shell commands like the one you described. For executing shell commands, PHP has the exec(), shell_exec(), and passthru() methods.
I suggest using the exec.
The following file, mautic-commands.php , contains the solution you want. Please Update the list of commands you want to group.
Thanks brother, that’s great. Now I find my host has disabled exec() so I’m having to go back to them, but I’m getting closer. Really appreciate your help, thank you!
You sure about that and not that your cronjob entry is interpreting the args as a new cmd?
I would first try to double quote the CMD.
i.e. * * * * * /usr/local/bin/php "/path/to/mautic/bin/console messenger:consume email"
If that fail, you don’t need to have exec to run a PHP script…
How to do it;
Create a shell file with that content:
#!/usr/bin/bash
# First CMD
/usr/local/bin/php /path/to/mautic/bin/console messenger:consume email
# Second CMD
/usr/local/bin/php /path/to/mautic/bin/console messenger:consume email
# Third CMD
/usr/local/bin/php /path/to/mautic/bin/console messenger:consume email
# Add more lines for more CMD
Save it and then run chmod a+x on it
From there, in your crontab, add your conrjob to run every now and then. * * * * * /path/to/your/shell/script
I’ll also suggest to make use of “flock” (probably already installed on your server). This would avoid overlapping the cronjob.
That fixed the issue for me. My Control Panel (which is a custom one, not CPanel) did have an option to enable exec() and other similar functions, so once I did that, all good. Your script worked great, thanks @rahul.shinde
Well actually I’m getting emails that Mautic is unpublishing my campaign:
“Due to repeated event failures, your [***]) campaign has been unpublished.”
I haven’t had time to look into this in detail yet, but was wondering if it was due to testing with dummy emails that can’t be delivered. Or could it be related to the messenger:consume email command??