# Problem with cron jobs

**URL:** <https://forum.mautic.org/t/problem-with-cron-jobs/8452>\
**Category:** Product Support\
**Created:** [May 9, 2017, 1:18pm UTC](https://forum.mautic.org/t/problem-with-cron-jobs/8452 "2017-05-09T13:18:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giuliusmautic12](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@giuliusmautic12](https://forum.mautic.org/u/giuliusmautic12)\
**Post date:** [May 9, 2017, 1:18pm UTC](https://forum.mautic.org/t/problem-with-cron-jobs/8452/1 "2017-05-09T13:18:37Z")

</div>

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](https://www.mautic.org/docs/setup/index.html)’;  
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

---

<div class="post-metadata">

**Author:** ![giuliusmautic12](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@giuliusmautic12](https://forum.mautic.org/u/giuliusmautic12)\
**Post date:** [May 9, 2017, 1:18pm UTC](https://forum.mautic.org/t/problem-with-cron-jobs/8452/2 "2017-05-09T13:18:37Z")

</div>

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](https://www.mautic.org/docs/setup/index.html)’;  
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

---

<div class="post-metadata">

**Author:** ![olafdammann](https://avatars.discourse-cdn.com/v4/letter/o/779978/32.png) [@olafdammann](https://forum.mautic.org/u/olafdammann)\
**Post date:** [May 9, 2017, 1:56pm UTC](https://forum.mautic.org/t/problem-with-cron-jobs/8452/3 "2017-05-09T13:56:49Z")

</div>

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

```auto
#!/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

---

<div class="post-metadata">

**Author:** ![giuliusmautic12](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@giuliusmautic12](https://forum.mautic.org/u/giuliusmautic12)\
**Post date:** [May 10, 2017, 2:30pm UTC](https://forum.mautic.org/t/problem-with-cron-jobs/8452/4 "2017-05-10T14:30:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giuliusmautic12](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@giuliusmautic12](https://forum.mautic.org/u/giuliusmautic12)\
**Post date:** [May 11, 2017, 5:16pm UTC](https://forum.mautic.org/t/problem-with-cron-jobs/8452/5 "2017-05-11T17:16:45Z")

</div>

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