aeroswat Posted March 24, 2010 Share Posted March 24, 2010 This will be the first one I set up. On my CPanel there is a place for these and the command it has to run at a certain time is php -f (directory for site) and then a blank box where I'm guessing I can put in a php file? Is this the correct way to do it? Will this run the php file that I put in there at whatever interval I choose? Link to comment https://forums.phpfreaks.com/topic/196352-cron-job/ Share on other sites More sharing options...
shlumph Posted March 24, 2010 Share Posted March 24, 2010 Yep Link to comment https://forums.phpfreaks.com/topic/196352-cron-job/#findComment-1031004 Share on other sites More sharing options...
aeroswat Posted March 24, 2010 Author Share Posted March 24, 2010 Yep Thank you Just didn't want to screw anything up and everything I googled said to use a -q switch with the php command. However I figured my web host wouldn't put that f switch in just to mess me up lol. One other question too maybe someone could answer in here. If I wanted to delete all the data in one table and replace it with data from another table while starting everything over would I do the following SQL queries: TRUNCATE TABLE tblLastYearsOrders INSERT INTO tblLastYearsOrders SELECT * FROM tblThisYearsOrders TRUNCATE TABLE tblThisYearsOrders Basically I want to set up a cron job once a year to reset my orders and move them into my back-up database so I can start fresh with new orders but still have the ability to look at previous years. Link to comment https://forums.phpfreaks.com/topic/196352-cron-job/#findComment-1031013 Share on other sites More sharing options...
aeroswat Posted March 24, 2010 Author Share Posted March 24, 2010 Also another thing I forgot to ask... I want this script to obviously only be run by the Cron job... How do i make it so that no one else can execute the script by just typing it into their web browser? Link to comment https://forums.phpfreaks.com/topic/196352-cron-job/#findComment-1031022 Share on other sites More sharing options...
JAY6390 Posted March 24, 2010 Share Posted March 24, 2010 If you want it to be run by only the cron, you can do a few things 1. Check the REMOTE_ADDR in $_SERVER 2. Since this will happen once a year, make sure the date is correct for the script to run (ie the first of january/31st december) 3. add some sort of key that you can pass as a param to the script to check I'd also just like to point out that I would personally have a table with ALL orders in it for last year and the years previous, so that you have all orders as well as the current years. You shouldn't be discarding this data unless you have it saved somewhere else also Link to comment https://forums.phpfreaks.com/topic/196352-cron-job/#findComment-1031024 Share on other sites More sharing options...
aeroswat Posted March 24, 2010 Author Share Posted March 24, 2010 If you want it to be run by only the cron, you can do a few things 1. Check the REMOTE_ADDR in $_SERVER 2. Since this will happen once a year, make sure the date is correct for the script to run (ie the first of january/31st december) 3. add some sort of key that you can pass as a param to the script to check I'd also just like to point out that I would personally have a table with ALL orders in it for last year and the years previous, so that you have all orders as well as the current years. You shouldn't be discarding this data unless you have it saved somewhere else also We only have need to keep data for orders up to 3 years so what I am trying to do is cycle them through like this delete previous year 3 put previous year 2 in previous year 3 delete previous year 2 put previous year 1 in previous year 2 delete previous year 1 put current year in previous year 1 delete current year Ya I was thinking about checking the date. Can I send it a get variable when using this command line cron job? If so how would I call like reset.php?res=somepasswordstring Link to comment https://forums.phpfreaks.com/topic/196352-cron-job/#findComment-1031027 Share on other sites More sharing options...
JAY6390 Posted March 24, 2010 Share Posted March 24, 2010 You would pass the argument in the command. check out the php CLI This article may also be of use to you http://articles.sitepoint.com/article/php-command-line-1 Link to comment https://forums.phpfreaks.com/topic/196352-cron-job/#findComment-1031090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.