Joomla (3.X) How to schedule a cron?

Question: How to schedule a cron on Joomla?

Sub question: I do not understand if there is a php file and code for writing? or should I install Unix Cron (not sure if I can with the host provider)?

Details: I created the component, I want it to run once a day.

+7
source share
2 answers

Hallelujah!

Here is the answer.

Stackoverflow is a huge help for me, I have greatly benefited from the responses of the participants, today I am very happy to participate in the community with this answer, and I hope that this will help developers like me who have no choice to work with Joomla.

So here is how to build a cron with Joomla.

, cron, unix cron. php. , Joomla.

/Cli

<?php

// Initialize Joomla framework
const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
    require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', dirname(__DIR__));
    require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';

require_once JPATH_BASE . '/includes/framework.php';

/**
 * Cron job 
 *
 */
class myCron extends JApplicationCli
{
    /**
     * Entry point for the script
     *
     * @return  void
     *
     * @since   2.5
     */
        public function doExecute()
        {

// YOUR CODE HERE
            require_once JPATH_BASE.'/administrator/components/com_mycom/helpers/XMLImporter.php';

            echo "CRON TASK START ";
        echo "\n"; // Use \n is you are executing the cron from the terminal.

            $instance = PropertyXMLImporter::instance();
            $instance->execute_import();

        echo "CRON TASK END ";
        echo "\n";
        }
    }

JApplicationCli::getInstance('myCron')->execute();

.

> crontab -e

vi, ZZ : q! , , ( Mac)

> export EDITOR=nano

> crontab -e

:

*/1 * * * * php /Applications/MAMP/htdocs/YOURPROJECT/PATH-TO-THE-CRON/cronTask.php

, ,

> crontab -l

*/1 * * * * - Cron, , : https://en.wikipedia.org/wiki/Cron

*/1, . , , . , 3 . 0 3 * * *

1: cron /1! (*/1 * * * *) (1 * * * *).

2: cron localhost " MySQL".

public $ host = '127.0.0.1';

public $ host = 'localhost'; , ** ! ...

3: , , , cron /cli. , , cron.

, - !

+10

cron cpanel cron cpanel :

/public_html/your_projects/cron.php

0

All Articles