ez.no / exponential / documentation / configuration / configuration / cron jobs
These documentation pages are no longer maintained. Please visit the new documentation site.
Cron jobs in Exponential are used to run workflows, notifications and other jobs which should be run periodically.
You can run cronjobs in Exponential with PHP compiled as CGI. Example of cronjob execution (linux) is shown below.
/usr/bin/php -C runcronjobs.php
This is the most comon place for the php executeable. If you have troubles finding your PHP executeable use:
whereis php sample output: php: /usr/bin/php /etc/php.ini /usr/lib/php /usr/include/php /usr/share/php /usr/share/man/man1/php.1
You can configure which cronjobs should be executed in settings/cronjobs.ini. Cron job scripts are placed in cronjobs/ in the Exponential root.
If you do not have PHP compiled as a command-line-version, but only as a webserver module, you must run your cronjobs by calling the runcronjobs.php by a HTTP request from a webbrowser. You can do this manually or scheduled by a cronjob on the same or some other server, using lynx or wget or w3m to call the URL.
Note that this is not secure, as someone could call the URL very often and overload the server.
You can combine the setup with a shell-driven call in order to be able to call the cronjobs, whenever you need them (for testing workflows, RSS imports etc etc).
So, you need to call "runcronjobs.php" by a HTTP request. In a "virtual host" Exponential setup, this will not be possible, because the rewrite rule will always redirect you to "index.php". In order to re-gain access to "runcronjobs.php, you can change the existing rule to "not change request to *.php" or introduce an additional RewriteRule.
First option would look somehow like this:
RewriteRule !\.(php|gif|css|jpg|png) /path/to/exponential/index.php
This will allow execution of any PHP script and so, should not be used.
Better, but still not perfect, is to introduce a rewrite rule to call the runcronjobs.php:
RewriteRule ^/mySecretCronURL$ /path/to/exponential/runcronjobs.php [L] RewriteRule !\.(gif|css|jpg|png)$ /path/to/exponential/index.php
The first line will look for a HTTP request to /mySecretCronURL and start the runcronjobs.php script; other requests are handled as usual (2nd line). This should do all the scheduled things and print some information about what it's doing to your webbrowser window. As this is no HTML, it will be ugly, so switch to "source code view" to see, what happened.
While this works, it's not secure, as everyone can call the URL, once it is know. I think, RewriteRules can be "conditional", which could secure that a bit by only using the RewriteRule for a know, static IP-Adress or so, but I'm not into this. Someone please add to this post, when he has more knowledge about it.
Finally, there is another method if you do not have cronjobs installed or CGI enabled php:
As long as your site is visited by your users, the index.php will always run each time a user request something from your eZ site. Ok, then let's make index.php to automatically invoke the cronjobs, add these two line to the bottom of index.php, just before the line: eZExecution::cleanup();
include_once( 'kernel/classes/notification/eznotificationeventfilter.php' ); eZNotificationEventFilter::process();
Using this method, you do not need to change the rewrite rule so it is as secure as before.
But still there is the problem of serious performance impacts: every time your user request a page, the cronjobs will run.
This can be solved if we only run the cronjobs every, say 2 hours, so we will extend above two lines to followings:
/* Run Notification Filters */ $notifyFilterLastRunTimeFile = 'ezfilternotify_last_runtime'; $filterAutoRunInterval = 7200; //2 hours $runFilter = false; if( file_exists($notifyFilterLastRunTimeFile) ) { if( time() - filemtime( $notifyFilterLastRunTimeFile ) > $filterAutoRunInterval ) { $runFilter = true; } } else $runFilter = true; if( $runFilter ) { include_once( 'kernel/classes/notification/eznotificationeventfilter.php' ); touch($notifyFilterLastRunTimeFile); eZNotificationEventFilter::process(); }
That's it. As long as your site is visited every 2 hours, your cronjobs will be executed properly (of course, if no one visit your site, you can not expect anything coming out from these piece of code).
Comments
run the cronjob using HTTP did not work for me
nigel dodd
Wednesday 22 December 2004 8:38:15 pm
A solution that did work for me is described in http://ez.no/community/bugs/patch_for_systems_without_phpcli
I would be intrigued to know why the solution described here ( http://www.ez.no/exponential/docum...onfiguration/configuration/cron_jobs ) did not work. It obviously runs eZNotificationEventFilter::process() but what does that do and why does it appear not to work for me?