tags:

views:

112

answers:

3

I'm working on a website for a client, in PHP/MySQL. They are a publisher, and the site needs to show whether the book you are looking at is in stock with their distributor.

The stock file is a CSV file on the distributor's FTP. This file is updated at a certain time every evening. So far I've written a script in PHP that copies the contents of the file to the web server. I'll then get the stock information from this and stick it in the MySQL books database.

Is there a way to make the file-transfer PHP script only run once a day, after the file has updated on the distributor's FTP? Is this the best way to do this?

+4  A: 

The conventional way to automate repeating tasks is to use cron. You can edit your cron configuration from the command line using crontab -e. The file follows the following format:

# .---------------- minute (0 - 59) 
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat 
# |  |  |  |  |
  *  *  *  *  *  command to be executed
Andrew Vit
+2  A: 

you will need to use a scheduled task if you are using a windows server, or a cronjob if you are on unix. Here is some info on using cron: http://www.clockwatchers.com/cron_main.html http://www.clickmojo.com/code/cron-tutorial.html and the win task scheduler: http://www.iopus.com/guides/winscheduler.htm

SimaWB
+1  A: 

The best way for dealing with such a scenario would be a cronjob as mentioned above, I had a similar predicament a year ago but the only difference being that I did not know when the file was going to come in and how many. I created a php script which monitored the ftp upload folder and which rand every 10 minutes and when every a file came in it would get processed(Read and data stored in a database) and after that I would then move it to another folder called processed and another called failed if it was not successfully reading the file. I hope this helps - I just thought I would share.

Ronald Conco