MyBB Community Forums

Full Version: Cron Job for Task
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(My apologies if this is posted in not the best section - feel free to move.)

Am trying to get a task run from a Cron job.
The task and fucntionality works absolutely fine if I either run it manually from my ACP Task manager - or if I set it up as a schedule and fire it by surfing around the forums.

However, I need this task to be run at a particular day/time on a week by week basis. Since my forums don't have a lot of traffic, I don't really want to leave it set as a MyBB schedule since if no users visit my forums, it wont run at the time I need it do.

Hence why I need to run it using Cron.
I have disabled the schedule of the task but for the life of me simply cant get it to run from a Cron job.
(I know Cron works as I can perform a simple email to be fired off at regular intervals)

The task ID is 22 and the command I am using is:

* * * * *  /usr/bin/php5 /htdocs/forums/task.php 22

(Whilst testing I have set the schedule interval for every minute - this will be changed when I confirm it works)

I dont see any error messages produced but nothing is every received.

Am I doing something totally stupid here.

Would really appreciate anybody giving me a clue as its making me very grey ! Huh
Just a bit more input from me on this one - and hoping that someone can assist.

I've worked out how to set up a cron job to launch task.php every 10 minutes using:
*/10 * * * * /usr/bin/curl http://www.mydomain/task.php  >/dev/null

However, I really need it to ONLY work on a particular task id
Have tried all sorts of ways, and can't get it to simply work on one task.

Have tried:
/usr/bin/curl http://www.mydomain/task.php 22  >/dev/null
/usr/bin/curl http://www.mydomain/task.php&id=22 >/dev/null
/usr/bin/curl http://www.mydomain/task.php&id=22 >/dev/null
/usr/bin/curl http://www.mydomain/task.php?id=22 >/dev/null
/usr/bin/curl http://www.mydomain/task.php?tid=22 >/dev/null

From what I can determine the cron cannot understand the MyBB TaskID element.
Can anyone give me any more pointers.
Thanks
If you use curl, it calls the "normal" task manager, because you are not in CLI mode.

Your first call (/usr/bin/php5 /htdocs/forums/task.php 22) might be ok, you may try to launch it by the hand (inconsole) with the same user you've defined your cron.
OK thanks.

If I omit the task ID, then the cron job runs fine - providing I have the task I am needing to run set as a scheduled task.
However if I disable the task from the MyBB Task Scheduler, and try to run the cron again nothing happens as it doesnt seem to handle the task id at then end.

Have also tried using quotes etc.
Peharps the trouble is in your task itself, it could be a lock trouble.
If you call the task.php in cli mode, with an task id, the system doesn't check if task is disabled or enabled. But it checks if the task is locked, and if it's locked less than 5 minutes before.

Can you post your task code ?
Thanks for your reply Crazycat.
I've also been testing with using one of the standard stock tasks with MyBB - 'Half Hourly Cleanup'  (Task ID 3) and cant get that to run either.

Have checked that no tasks are locked.

I have determined what my AbsolutePath is set to - and this is: /homepages/7/dxxxxxx/htdocs/forums

Am using PuTTY in command mode and if I try:
/usr/bin/php5  /homepages/7/dxxxxxx/htdocs/forums/task.php   I get:


X-Powered-By: PHP/5.2.17
Content-type: image/gif
Expires: Sat, 1 Jan 2000 01:00:00 GMT
Last-Modified: Tue, 03 Mar 2015 12:10:59 GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache


If I then add a task ID at the end - e.g
/usr/bin/php5  /homepages/7/dxxxxxx/htdocs/forums/task.php 3

I get:


X-Powered-By: PHP/5.2.17
Content-type: image/gif
Expires: Sat, 1 Jan 2000 01:00:00 GMT
Last-Modified: Tue, 03 Mar 2015 12:12:34 GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache

GIF89aÿÿÿ!ù,D;

Notice the end bit which shows: GIF89aÿÿÿ!ù,D;

However checking the SQL database, the lastrun timestamp is the same - and the task doesn't run.

If I then try adding quote marks as in:
/usr/bin/php5  "/homepages/7/dxxxxxx/htdocs/forums/task.php 3"

I get:
Status: 404 Not Found

X-Powered-By: PHP/5.2.17
Content-type: text/html

No input file specified.



Hope that all makes sense !
It seems like the PHP_SAPI wasn't ok (not "cli").
Try edit the task.php file and add at the beginning of the file:
echo '***', var_dump(PHP_SAPI), '***';
return;

Then, retry :
/usr/bin/php5  /homepages/7/d338192408/htdocs/forums/task.php 3

You may have the correct value to set in line #35

Then, remove the two lines and correct the PHP_SAPI check
OH MY WORD !!!!  You've cracked it for me.

I've been trying to get this working for days (if not a couple of weeks) and its really been getting me down Sad

Crazycat - you are an absolute star and I really appreciate the time you spent looking at this.

I've done loads of searching around about the MyBB task system and never came across the fix that you suggested.
Am sure a few other users will find this useful.

Big kiss ! Heart
Thanks :$

I'm a little bit curious, can you give the PHP_SAPI you have ?

@developper team : peharps it could be interesting in task.php to have different check:

function is_cli() {
    return (
        !array_key_exists('SERVER_SOFTWARE', $_SERVER)
        && (PHP_SAPI === 'cli' || !array_key_exists('REMOTE_ADDR', $_SERVER))
    );
}
if (is_cli()) {
Sure - it was originally showing as

if(PHP_SAPI == "cli")

Modified to:

if(PHP_SAPI == "cgi-fcgi")

(Is that what you needed?)
Pages: 1 2