Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Alex4108 on January 16, 2012, 06:39:58 PM

Title: Running a script through cron
Post by: Alex4108 on January 16, 2012, 06:39:58 PM
Hey SMF!

I want to run my script through cron.  Its an addon to an awards plugin, that checks users registration dates and issues time based awards.  My script is including SSI.php, however I get this error when the script actually runs in cron:

PHP Notice:  Undefined index:  REMOTE_ADDR in /home/rgclan/public_html/bb/Sources/ManageSearchEngines.php on line 468

Halp?
Title: Re: Running a script through cron
Post by: Arantor on January 16, 2012, 06:53:18 PM
Well, it's a bit hackish but just before your custom script loads SSI.php, you can add:
$_SERVER['REMOTE_ADDR'] = '';
Title: Re: Running a script through cron
Post by: Alex4108 on January 16, 2012, 07:02:00 PM
Quote from: arrowtotheknee on January 16, 2012, 06:53:18 PM
Well, it's a bit hackish but just before your custom script loads SSI.php, you can add:
$_SERVER['REMOTE_ADDR'] = '';

I don't think you can modify $_SERVER variables.

Oh well, I followed this: http://www.simplemachines.org/community/index.php?topic=329894.0 and got it working

~Solved
Title: Re: Running a script through cron
Post by: Arantor on January 16, 2012, 07:40:08 PM
Yes, you can modify $_SERVER variables. Once they enter PHP, they're just regular variables in a global scope.

Still, there is an advantage to using cron vs scheduled tasks - cron will always run, while scheduled tasks can only run if the forum is actively loaded during that time (since browsing the forum will trigger the task check/run), mind you if the search engines are viewing your site it usually isn't a problem.