# Script to run Mautic (Symfony) commands from a URL.

**URL:** <https://forum.mautic.org/t/script-to-run-mautic-symfony-commands-from-a-url/2397>\
**Category:** Product Support\
**Created:** [September 23, 2015, 3:21pm UTC](https://forum.mautic.org/t/script-to-run-mautic-symfony-commands-from-a-url/2397 "2015-09-23T15:21:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ninjoan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ninjoan/32/1005_2.png) [@ninjoan](https://forum.mautic.org/u/ninjoan)\
**Post date:** [September 23, 2015, 3:21pm UTC](https://forum.mautic.org/t/script-to-run-mautic-symfony-commands-from-a-url/2397/1 "2015-09-23T15:21:04Z")

</div>

I follow the instruction provide by @escopecz but i get this error.

Code:

[RuntimeException] Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public\_html/marketing/commands.php" at line 48.

  
so i download the commands.php file from GitHub [](https://gist.github.com/escopecz/9a1a0b10861941a457f4/archive/aea92f72f089408d6b6dac63493d72b1f7556617.zip)  
  
and know i get this

Code:

[RuntimeException] Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public\_html/marketing/commands.php" at line 59.

---

<div class="post-metadata">

**Author:** ![ninjoan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ninjoan/32/1005_2.png) [@ninjoan](https://forum.mautic.org/u/ninjoan)\
**Post date:** [September 23, 2015, 3:21pm UTC](https://forum.mautic.org/t/script-to-run-mautic-symfony-commands-from-a-url/2397/2 "2015-09-23T15:21:04Z")

</div>

I follow the instruction provide by @escopecz but i get this error.

`[RuntimeException]                                                                                                                     
  Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public_html/marketing/commands.php" at line 48. `

so i download the commands.php file from GitHub [](https://gist.github.com/escopecz/9a1a0b10861941a457f4/archive/aea92f72f089408d6b6dac63493d72b1f7556617.zip)

and know i get this

`[RuntimeException]                                                                                                                     
  Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public_html/marketing/commands.php" at line 59. `

---

<div class="post-metadata">

**Author:** ![ninjoan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ninjoan/32/1005_2.png) [@ninjoan](https://forum.mautic.org/u/ninjoan)\
**Post date:** [September 23, 2015, 3:27pm UTC](https://forum.mautic.org/t/script-to-run-mautic-symfony-commands-from-a-url/2397/3 "2015-09-23T15:27:31Z")

</div>

I think i fix it. Copy this Code and remember change ILoveMAUTIC

[quote]\<?php

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

$link = “http://$\_SERVER[HTTP\_HOST]$\_SERVER[REQUEST\_URI]”;  
$allowedTasks = array(  
‘cache:clear’,  
‘mautic:leadlists:update’,  
‘mautic:campaigns:update’,  
‘mautic:campaigns:trigger’,  
‘mautic:email:process’,  
‘mautic:fetch:email’,  
‘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];  
}  
}

require\_once **DIR**.’/app/bootstrap.php.cache’;  
require\_once **DIR**.’/app/AppKernel.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();  
}  
[/quote]

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [September 23, 2015, 3:35pm UTC](https://forum.mautic.org/t/script-to-run-mautic-symfony-commands-from-a-url/2397/4 "2015-09-23T15:35:25Z")

</div>

For the rest of the world, @ninjoan is talking about this script:

[https://gist.github.com/escopecz/9a1a0b10861941a457f4](https://gist.github.com/escopecz/9a1a0b10861941a457f4)

If I compared your version of the script correctly, you removed this row:

```auto
echo '<h3>Executing ' . implode(' ', $args) . '</h3>';
```

And it no longer throws this error:

`[RuntimeException]                                                                                                                     
  Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public_html/marketing/commands.php" at line 59. `

If that’s correct, well great you’ve solved it. It doesn’t make much sense to me, but that’s not the first or the last wonder in PHP world for me 🙂

---

<div class="post-metadata">

**Author:** ![ninjoan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ninjoan/32/1005_2.png) [@ninjoan](https://forum.mautic.org/u/ninjoan)\
**Post date:** [September 23, 2015, 3:40pm UTC](https://forum.mautic.org/t/script-to-run-mautic-symfony-commands-from-a-url/2397/5 "2015-09-23T15:40:33Z")

</div>

I hope this work for another user with problem like me.

Thanks @escopecz for be so patience.

Also there is any way to get in touch with David Hurley?

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [February 2, 2020, 10:58pm UTC](https://forum.mautic.org/t/script-to-run-mautic-symfony-commands-from-a-url/2397/6 "2020-02-02T22:58:24Z")

</div>


