Mautic Community Forums

Problem with cron jobs

Hi

We are using version 2.8.0 of mautic and for cron jobs we use the php script reported below.

Code:
<?php

if (!isset($_GET[‘CampCoFi’])) {
echo ‘The secret phrase is wrong.’;
die;
}

$link = “http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”;
$allowedTasks = array(
‘mautic:campaigns:trigger’,
‘mautic:campaigns:rebuild’,
‘mautic:iplookup:download’,
‘mautic:emails:send’,
‘mautic:email:fetch’,
‘mautic:integration:fetchleads -i Salesforce’,
‘mautic:segments:update’,
‘doctrine:migrations:migrate’,
‘doctrine:schema:update --dump-sql’,
‘doctrine:schema:update --force’
);

if (!isset($_GET[‘task’])) {
echo ‘Specify what task to run. You can run these:’;
foreach ($allowedTasks as $task) {
$href = $link . ‘&task=’ . urlencode($task);
echo ‘
’ . $href . ‘’;
}
echo ‘
Read more’;
echo ‘
Please, backup your database before executing the doctrine commands!’;
die;
}
$task = urldecode($_GET[‘task’]);
if (!in_array($task, $allowedTasks)) {
echo ‘Task ’ . $task . ’ is not allowed.’;
die;
}
$fullCommand = explode(’ ‘, $task);
$command = $fullCommand[0];
$argsCount = count($fullCommand) - 1;
$args = array(‘console’, $command);
if ($argsCount) {
for ($i = 1; $i <= $argsCount; $i++) {
$args[] = $fullCommand[$i];
}
}
echo ‘

Executing ’ . implode(’ ‘, $args) . ‘

’;
require_once DIR.’/app/bootstrap.php.cache’;
require_once DIR.’/app/AppKernel.php’;
require DIR.’/vendor/autoload.php’;
use SymfonyBundleFrameworkBundleConsoleApplication;
use SymfonyComponentConsoleInputArgvInput;
use SymfonyComponentConsoleOutputBufferedOutput;
defined(‘IN_MAUTIC_CONSOLE’) or define(‘IN_MAUTIC_CONSOLE’, 1);
try {
$input = new ArgvInput($args);
$output = new BufferedOutput();
$kernel = new AppKernel(‘prod’, false);
$app = new Application($kernel);
$app->setAutoExit(false);
$result = $app->run($input, $output);
echo “
n”.$output->fetch().’
’;
} catch (Exception $exception) {
echo $exception->getMessage();
}
If we try to execute a task we obtain the following error: Fatal error: Class 'SymfonyComponentHttpKernelKernel' not found in /web/htdocs/www.robotics40.it/home/campcofi/app/AppKernel.php on line 24
The version of PHP of our hosting is 5.6.30.
This problem avoid our mautic campaign to execute the designed workflow.
We need urgently to fix this problem because we are preparing a campaign for one of our customers and we have to start that as soon as possible.
Thank you in advance for your support.
Giulio

Hi
We are using version 2.8.0 of mautic and for cron jobs we use the php script reported below.

[code]<?php

if (!isset($_GET[‘CampCoFi’])) {
echo ‘The secret phrase is wrong.’;
die;
}

$link = “http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”;
$allowedTasks = array(
‘mautic:campaigns:trigger’,
‘mautic:campaigns:rebuild’,
‘mautic:iplookup:download’,
‘mautic:emails:send’,
‘mautic:email:fetch’,
‘mautic:integration:fetchleads -i Salesforce’,
‘mautic:segments:update’,
‘doctrine:migrations:migrate’,
‘doctrine:schema:update --dump-sql’,
‘doctrine:schema:update --force’
);

if (!isset($_GET[‘task’])) {
echo ‘Specify what task to run. You can run these:’;
foreach ($allowedTasks as $task) {
$href = $link . ‘&task=’ . urlencode($task);
echo ‘
’ . $href . ‘’;
}
echo ‘
Read more’;
echo ‘
Please, backup your database before executing the doctrine commands!’;
die;
}
$task = urldecode($_GET[‘task’]);
if (!in_array($task, $allowedTasks)) {
echo ‘Task ’ . $task . ’ is not allowed.’;
die;
}
$fullCommand = explode(’ ‘, $task);
$command = $fullCommand[0];
$argsCount = count($fullCommand) - 1;
$args = array(‘console’, $command);
if ($argsCount) {
for ($i = 1; $i <= $argsCount; $i++) {
$args[] = $fullCommand[$i];
}
}
echo ‘

Executing ’ . implode(’ ‘, $args) . ‘

’;
require_once DIR.’/app/bootstrap.php.cache’;
require_once DIR.’/app/AppKernel.php’;
require DIR.’/vendor/autoload.php’;
use SymfonyBundleFrameworkBundleConsoleApplication;
use SymfonyComponentConsoleInputArgvInput;
use SymfonyComponentConsoleOutputBufferedOutput;
defined(‘IN_MAUTIC_CONSOLE’) or define(‘IN_MAUTIC_CONSOLE’, 1);
try {
$input = new ArgvInput($args);
$output = new BufferedOutput();
$kernel = new AppKernel(‘prod’, false);
$app = new Application($kernel);
$app->setAutoExit(false);
$result = $app->run($input, $output);
echo “
n”.$output->fetch().’
’;
} catch (Exception $exception) {
echo $exception->getMessage();
}[/code]
If we try to execute a task we obtain the following error: Fatal error: Class ‘SymfonyComponentHttpKernelKernel’ not found in /web/htdocs/www.robotics40.it/home/campcofi/app/AppKernel.php on line 24
The version of PHP of our hosting is 5.6.30.
This problem avoid our mautic campaign to execute the designed workflow.
We need urgently to fix this problem because we are preparing a campaign for one of our customers and we have to start that as soon as possible.
Thank you in advance for your support.
Giulio

Hi @giuliusmautic12
Are you sure, that PHP-scripts can work for Mautic?
According to https://www.mautic.org/docs/en/setup/cron_jobs.html I build this Script, whatworks:

#!/bin/sh
# V.2.3
# (c) April 2017, OLAF KAPINSKI
# SOLOPRENEUR.technology
# Based on https://www.mautic.org/docs/en/setup/cron_jobs.html

date +"%d.%m.%Y, %H:%M:%S" > /pathtomautic/mautic/df-scripts/all-crons.log

cd /pathtomautic/mautic/app

#--- Segments ---------------------------------
echo "1/6 --- To keep the segments current: --------------------------------------" >> /pathtomautic/mautic/df-scripts/all-crons.log
/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:segments:update >> /pathtomautic/mautic/df-scripts/all-crons.log

echo "2/6 --- Send Scheduled Broadcasts (e.g. segment emails) --------------------" >> /pathtomautic/mautic/df-scripts/all-crons.log
#https://www.mautic.org/community/index.php/6553-scheduled-broadcasts-didn-t-send/0
/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:broadcasts:send >> /pathtomautic/mautic/df-scripts/all-crons.log
sleep 2m
#----------------------------------------------

#--- Campaigns --------------------------------
echo "3/6 --- To keep campaigns updated with applicable contacts: ----------------" >> /pathtomautic/mautic/df-scripts/all-crons.log
/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:campaigns:rebuild >> /pathtomautic/mautic/df-scripts/all-crons.log
sleep 2m

echo "4/6 --- To execute campaigns events: ---------------------------------------" >> /pathtomautic/mautic/df-scripts/all-crons.log
/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:campaigns:trigger >> /pathtomautic/mautic/df-scripts/all-crons.log

echo "5/6 --- To send frequency rules rescheduled marketing campaign messages: ---" >> /pathtomautic/mautic/df-scripts/all-crons.log
/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:messages:send >> /pathtomautic/mautic/df-scripts/all-crons.log
#----------------------------------------------

#--- GoToMeeting.com --------------------------
echo "6/6 --- To syncronize the events in GoToMeeting.com: -----------------------" >> /pathtomautic/mautic/df-scripts/all-crons.log
/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console citrix:sync >> /pathtomautic/mautic/df-scripts/all-crons.log
#----------------------------------------------

#--- Optional ---------------------------------
#Process Email Queue
#Mautic is not set to queue email.
#/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:emails:send >> /pathtomautic/mautic/df-scripts/all-crons.log
#sleep 2m

#Fetch and Process Monitored Email
#No mailboxes are configured.
#/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:email:fetch >> /pathtomautic/mautic/df-scripts/all-crons.log
#sleep 2m

#Social Monitoring
#No published monitors found. Make sure the id you supplied is published
#/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:social:monitoring >> /pathtomautic/mautic/df-scripts/all-crons.log
#sleep 2m

#Webhooks
#Webhook Bundle is in immediate process mode. To use the command function change to command mode.
#/usr/bin/env -i /usr/local/bin/php7-70STABLE-CLI console mautic:webhooks:process >> /pathtomautic/mautic/df-scripts/all-crons.log
#----------------------------------------------

The “optional” Path is just in case I need it once. Maybe try this one?
CU
OLAF

Thank you OLAF, but we do not have control over the server. Our server is Aruba. The cronjob code worked for the version of Mautic 2.5 but not 2.8.

Do you have another solution?
Thank you!
Giulio

Yes, Google is our friend:)
Thank you very much for your indication!
Giulio