Page 1 of 1

cron??

Posted: Wed May 24, 2006 11:55 am
by pleigh
ok here's the idea...i have a directory in my site where i dump my pdf files, lets call the directory myPDFs...inside the directory, i have one.pdf, two.pdf, three.pdf...now, every week, i need to update and replace the content of that directory, having the same file names, overwriting the previous files...these files will be coming from another directory, lets call it my2ndPDFs...i want it to update automatically instead of uploading every week the updated files....i was thinking of cron, but i am not very familiar with it..and don't really know where to start...is there any function that can do this??with or without the cron??i really don't know cron so i may have the wrong impression...please guide me...thanks in advance... :)

Posted: Wed May 24, 2006 12:05 pm
by Flamie
By personal experience, I say NEVER rely on cron for anything.
I personally always do my "cron jobs" thru php, using time() or date(), so like in your index.php (which I assume would be the page most visited on your site) just make a check if 1 week has passed since your last "updated" and if it has just run the php script to do the things you wanna do.

Posted: Wed May 24, 2006 12:32 pm
by pleigh
thanks for the reply...i was also thinking of doing that...but to start with the code is really stucking me...i dont know where to start.. Embarassed ...any functions for this??or class maybe??

Posted: Wed May 24, 2006 1:11 pm
by Flamie
well personally for all of my sites I have a config table with 2 fields <name> <value> in which I store all the "1 time" information related to the site.
So for your case you could have like:
lastupdate -> time of last update

so lets say you update now and store time().
in your index you can do this:

Code: Select all

$lastupdate = mysql_result(mysql_query("SELECT value FROM config WHERE name='lastupdate'"),0);
then you know that in 1 week heres 604800 seconds, so:

Code: Select all

$timenow = time();
if($lastupdate - $timenow > 604800) //more than 1 week passed
{
        //do your stuff here
        //and update the database
        mysql_query("UDPATE config SET value='$timenow'  WHERE name='lastupdate'");
}

Posted: Wed May 24, 2006 2:08 pm
by pickle
I use cron all the time to get stuff done - it works great if you set it up properly. For something like this, I'd make a PHP script that moves all the PDFs from my2ndPDFs to myPDFs

Code: Select all

$from_path = '/var/www/mypdfs';
$to_path = '/var/www/my2ndpdfs';

chdir($from_path);
$files = glob('*.pdf');

foreach($files as $filename)
{
  rename($from_path.'/'.$filename,$to_path.'/'.$filename);
}
Set the permissions so that it's executable, then toss it in your cron.weekly directory. Done.

Posted: Thu May 25, 2006 4:58 am
by JayBird
Flamie wrote:By personal experience, I say NEVER rely on cron for anything.
Hmmm...bit of a flipant remark. Used correctly it the THE best way of scheduling task, when the tasks are time critical.

You alternative method is no use for time critical tasks.