Setting Up Cron Job Script (include just the 'functions & variables')

Permalink
Hi all,
I'm trying to setup a cron job.

I've managed to test the script and it works fine, but I need to clear the cache.

Here is the sample cron job script

<?php
   include("../config/site.php");
   $sql_file='concrete.txt';
   if (file_exists($sql_file)){
      $output=array();
      $cmd='mysql -u'.escapeshellcmd(DB_USERNAME).' -p'.escapeshellcmd(DB_PASSWORD).' '.escapeshellcmd(DB_DATABASE).' < '.$sql_file.' 2>&1';
      exec($cmd,$output);
echo "<pre>cmd:".htmlspecialchars($cmd)."\n\n"."output:\n".htmlspecialchars(implode("\n",$output))."\n</pre>";
   }
   copy('sitemap.xml','../sitemap.xml');
   $ca = new Cache();
   $ca->flush();


Now obviously I can't call the cache class without the proper include

I tried at the top to replace 'include("../config/site.php");' with 'include("../concrete/dispatcher.php");'

However, this just makes it bring up the install page.

How can I include just the 'functions & variables' of concrete without getting redirected to an install or 'page does not exist'

I installed the cron job into a /_cron/ folder (from the root so itshttp://www.thedomain.com/_cron/)

[edit]
I realize i could use the add-on, but I think this is relevant for anyone who wants to make 'hacks'

 
ryan replied on at Permalink Reply
ryan
You may want to start by copying the dispatcher.php file from the start, down to about line 89 and then changing:
dirname(__FILE__)
to the path to your /concrete folder.
briand replied on at Permalink Reply
I was hoping to keep the dispatch script centralized. Personally I don't like copy-pasting when they've used BASE_DIR constants

Maybe I could just change the BASE_DIR constant?
ryan replied on at Permalink Reply
ryan
Well, if you're interested in using c5 the way it was intended, use a concrete5 Job and setup your cron job to call the maintenance script with wget.

Also a php file: /tools/test.php will get loaded with all the proper includes and without the theme/layout stuff when requested at:www.www.yoursite.com/index.php/tools/test...
briand replied on at Permalink Reply
So there is no way to just 'grab' the concrete 'system' for use with one script?

I don't want to make it too hack. I'm hoping that there was a way to just change a variable or something (like BASE_DIR) and just go from there. Maybe I should run the cron-job from the root :S
briand replied on at Permalink Reply
Okay so it was a lot easier than I expected.

I setup my _cron/ directory. The first 3 lines are as follows:
<?php
define("DIR_BASE",'..');
define('C5_ENVIRONMENT_ONLY', true);
include("../index.php");


And thats it!
No Install Page! No 'Page Not Found'! and all it took was 3 simple lines.

I was finding that since everything was expected to be taken from the root, that including dispatch.php instead of index.php was causing the headache.
zhilong replied on at Permalink Reply
hi briand,
i use that three line code , & put it on the top line of code.
i get the following error?
Warning: ini_set() [function.ini-set]: A session is active. You cannot change the session module's ini settings at this time in E:\wamp\www\concrete5_rest\concrete\startup\session.php on line 9

do i miss anything?

thanks
briand replied on at Permalink Reply
Could you post your code.
Sounds like you did a session start or set cookie earlier. than the concrete code. I was setting up a cron job and didn't have to concern myself with sessions :(

[EDIT]
Don't forget to check for white space before you <?php
zhilong replied on at Permalink Reply
Hello,

i just create a php file in web root tools/test.php, with the code put inside
<?php
define("DIR_BASE",'..');
define('C5_ENVIRONMENT_ONLY', true);
include("../index.php");
?>

i run in browser by this path
http://localhost/concrete5_rest/tools/test.php...

then got
A session is active. You cannot change the session module's ini settings at this time in E:\wamp\www\concrete5_rest\concrete\startup\session.php on line 9

if run by this
http://localhost/concrete5_rest/index.php/tools/test...
then got
Unable to open WampServer's config file, please change path in index.php file

where do you create the php file :) include these 3 line codes?
by the way, which index.php do you mean and why include ../index.php?


thanks a lot, your help will appreciated :)
briand replied on at Permalink Reply
if you read what I posted above,
I created a _cron/ directory in the root of my site.

By your setup you should do concrete5_rest/_test/test.php

However, that error you are getting is unrelated. I think you have some white space near your php containers.