[email protected]
Twitter
LinkedIn
GitHub
  • Services
  • Blog
  • Repositories
  • GitHub
  • Resume
  • Contact
Product was added to your cart

Cart

Run Symfony2 command from cronjobs in CPanel on a shared host

September 18, 2015Back-End, Tricksjfadev

Let's see how to program tasks scheduled in CPanel shared hosting to run custom commands of Symfony2.

In our example we will have the following file structure of our Symfony project in our shared server:

/home/{username}
|
|- /app
|- /src
|  |
|  |- /AppBundle
|  |
|  |- /Command
|     |
|     |-TestCommand.php
|
|- /vendor
|- /public_html
|  |
|  |- app.php
|
|- test_command.log

/src/AppBundle/Command/TestCommand.php

<?php

namespace AppBundle\Command; 

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 
use Symfony\Component\Console\Input\InputArgument; 
use Symfony\Component\Console\Input\InputInterface; 
use Symfony\Component\Console\Input\InputOption; 
use Symfony\Component\Console\Output\OutputInterface; 

class TestCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this->setName('my:test:run');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Welcome World!');
    }
}

Now we run each time our command and to save the result in the test_command.log file. To do this just go in our CPanel:

Home >  Advanced > Cron Jobs

Minute: 0
Hour: *
Day: *
Month: *
Weekday: *

Command: /usr/bin/php -q /home/{username}/app/console my:test:run >/home/{username}/test_command.log

Replace {username} by your user name on your shared hosting account.

: Commands, Console, CPanel, Cronjobs, Framework, PHP, Symfony2

Services

  • Excel2chatGPT $10.00 $5.00
  • Bot Tok $5.00
  • Fix bugs in your Wordpress Site $40.00 $30.00 / hr
  • Fix bugs in your PHP Symfony App $50.00 / hr
  • Tasks Automation using Node.js $50.00 / hr

Blog

  • Jfa Whatsapp Chatbot
  • TikTok Bot
  • Bot Tok (TikTok Bot)
  • Excel2chatGPT (Excel to ChatGPT)
  • Web Scraping and Automation Resources

Explore

  • Los Mejores Top 10
  • Upcycling Fashion BCN
Twitter
LinkedIn
GitHub

© 2013-2023 Jordi Fernandes Alves (@jfadev)