Joomla (3.X) How to schedule a cron? -
question : how schedule cron on joomla ?
sub question : don't understand there php file , code write ? or should setup unix cron (not sure can host provider) ?
details : i've made component, want component execute once day.
complaint / troll / can skip : joomla documentation terrible ! can't believe there nothing explain how outdated information 2007 or outdated project (jcron scheduler). instaled full of bugs , unfriendly plugin jprc cronjobs no documentation (yeah!) found 2 pages configure : https://www.ostraining.com/blog/joomla/jprc-cronjobs/ http://dashhelp.com/home/joomla-blog/114-jprc-cronjobs-cron-for-joomla-websites plugin says ok, in fact doesn't run , there no log. log buttons frozen. when had same wordpress took me 30min ... on joomla after 1h30 haven't find out how do. sorry complaining, i've got fustrated on joomla project ! mvc architecture things in joomla. doc , ressource crap ! pfff feel better now, if nobody never read this.
hallelujah !
here answer.
stackoverflow huge me, have benefited anwsers of members, today happy participate community answer , hope developers me have no choice of working joomla.
so here how build cron joomla.
as elin says, there no cron builded in have use unix cron. cron call php script. make script work need load joomla framework.
you can exemple in /cli
here cron
<?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'; } // framework. require_once jpath_libraries . '/import.legacy.php'; // bootstrap cms libraries. require_once jpath_libraries . '/cms.php'; // load configuration require_once jpath_configuration . '/configuration.php'; require_once jpath_base . '/includes/framework.php'; /** * cron job * */ class mycron extends japplicationcli { /** * entry point script * * @return void * * @since 2.5 */ public function doexecute() { // code here require_once jpath_base.'/administrator/components/com_mycom/helpers/xmlimporter.php'; echo "cron task start "; echo "\n"; // use \n executing cron terminal. $instance = propertyxmlimporter::instance(); $instance->execute_import(); echo "cron task end "; echo "\n"; } } japplicationcli::getinstance('mycron')->execute();
now need schedule cron.
open terminal , type
> crontab -e
if opened vi text editor can press zz or :q! exit type better text editor (on mac)
> export editor=nano
then
> crontab -e
and add line :
*/1 * * * * php /applications/mamp/htdocs/yourproject/path-to-the-cron/crontask.php
you can check ok typing
> crontab -l
*/1 * * * * cron schedule syntax, check here read : https://en.wikipedia.org/wiki/cron
in our case used */1 trigger every minitues test purpose. of course want change when it's working. in case want run everyday @ 3am. changed 0 3 * * *
important 1 : launch cron job every minute test purpose don't forget /1 ! ( */1 * * * * ) not same (1 * * * *) . waiste bit of time on 1 ;)
important 2 : if error while excecution cron on localhost "could not connect mysql." change configuration.php with
public $host = '127.0.0.1';
instead of public $host = 'localhost'; yes 1 bi**h ! lost few hours on ...
important 3 : code wrote above, if put cron in /cli. i'm not sure best place, remember adapt path cron location.
i hope !
Comments
Post a Comment