xoops forums

kerkyra

Just can't stay away
Posted on: 2011/12/1 16:33
kerkyra
kerkyra (Show more)
Just can't stay away
Posts: 553
Since: 2005/2/14
#1

How to create a cron in Xoops

Does anybody know how to create o cron job in xoops? I have made an effort but it only runs through the web browser.

If i set it up to run from the server it gets stuck and i think the problem is protector or something like that.

Any ideas what i should include in the header? Or not include...

Mamba

Moderator
Posted on: 2011/12/1 20:38
Mamba
Mamba (Show more)
Moderator
Posts: 10933
Since: 2004/4/23
#2

Re: How to create a cron in Xoops

You can take a look at XoopsCare, which I think, provided this kind of feature.

Also, Wishcraft is using cron jobs in his TwitterBomb module, but I don't know if he is creating those jobs, or if they are created manually first and then he is just using them.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

deka87

Friend of XOOPS
Posted on: 2011/12/1 20:55
deka87
deka87 (Show more)
Friend of XOOPS
Posts: 1124
Since: 2007/10/5
#3

Re: How to create a cron in Xoops

cron is also run in the subscription module by thirdeye software. you can take a look on it too
Mind anchors

redheadedrod

Home away from home
Posted on: 2011/12/2 4:43
redheadedrod
redheadedrod (Show more)
Home away from home
Posts: 1296
Since: 2008/2/26
#4

Re: How to create a cron in Xoops

To create a Cron with Xoops the method is to put PHP code into a block that is invisible but include it in every page.

Not sure exactly how to do it but that is the method with xoopcare and some others. That PHP code then calls your Cron events.

You could theoretically do that by including code in your theme I suppose as well and might be easier to do. Something that is done all the time.

Problem is with the code above it will be a hit on systems that have a lot of users because it will be run every time someone updates a page. Even cached it could produce some big hits on a big site.

Thinking there might be a better way but not sure of the code to do it...
If you place code in your theme that looked at a flag to see if it needed to be updated then called an external script and reset that flag then run the cron it could be done that way. If you do it with JavaScript and an Ajax call you could do it in the back ground and the user never would see a delay.


Attending College working towards Bachelors in Software Engineering and Network Security.

kerkyra

Just can't stay away
Posted on: 2011/12/2 11:25
kerkyra
kerkyra (Show more)
Just can't stay away
Posts: 553
Since: 2005/2/14
#5

Re: How to create a cron in Xoops

thanks for the replies mates! I'll give it a try and see what i can do.
if i find anything usefull i'll post it here :)
www.guidemap.gr - Beta is out...

anderssk

Quite a regular
Posted on: 2011/12/2 20:36
anderssk
anderssk (Show more)
Quite a regular
Posts: 335
Since: 2006/3/21
#6

Re: How to create a cron in Xoops

I do have a cronjob, but thats inside Cpanel (webhost admin panel)
It create one file of all mails, distribution lists, domain files (and subdomain) and of course all databases.
The file is sendt trough SFTP to my private NAS server and from the NAS I can pick files and databases to my localhost machine for testing.

If you use Cpanel I can help set this up.

kerkyra

Just can't stay away
Posted on: 2011/12/3 13:05
kerkyra
kerkyra (Show more)
Just can't stay away
Posts: 553
Since: 2005/2/14
#7

Re: How to create a cron in Xoops

unfortunately i'm on plesk, i did something tha partially worked. I could use pure php to do this, but i want to include the xoops core so i can use some of its functionality.

It seems that there is something wrong with protector and/or the debugging information and for some reason i cant turn them off while running the cron... I'm not sure about this, i'm looking into it and trying things (trial and error).

If i figure it out i will post my observations here for the rest to have something to start with. :)
www.guidemap.gr - Beta is out...

kerkyra

Just can't stay away
Posted on: 2011/12/6 11:09
kerkyra
kerkyra (Show more)
Just can't stay away
Posts: 553
Since: 2005/2/14
#8

Re: How to create a cron in Xoops

i managed to figure this out, so here are my observations.

if you would like to run a cron job and use existing xoops functions, constants etc you would have to

1. include the mainfile.php
Quote:
include_once("root_path/httpdocs/mainfile.php");

where root_path is the absolute root path to your site

2. include the xoopslogger class and disable it (in case it is on)
Quote:

include_once XOOPS_ROOT_PATH.'/class/logger/xoopslogger.php';
$xoopsLogger =& XoopsLogger::getInstance();
$xoopsLogger->activated = false;
error_reporting(0);

as you can see i disabled error reporting as well, this is not mandatory (i think) but I did it anyway since I finished my debugging.

3. set the cron in your cpanel/plesk or whatever

Thats actually it. Now you can use any core functionality like xoops_load(), $xoopsDB etc, or load any languages on the fly as we would do in a module function.

I implemented this for a newsletter module i'm writing and its working fine so far. I hope it helps someone.

Maybe when i'm done with the module i will share it with the rest, although it is designed to serve my websites needs, and its based on the same logic as my Xoops Global RSS Hack/Solution.

I just want to share the logic.

Both global RSS and Newsletter functionality is missing from xoops but that doesn't mean we cant have it :) (without touching core files)