• Forum
  • Lounge
  • PHP - Scheduling a sync up every so ofte

 
PHP - Scheduling a sync up every so often

Dec 10, 2010 at 10:43pm
Hey everyone, this is a PHP quesiton, and not really a C++ question, but I don't really have any contacts for PHP questions so I thought I'd ask here =x


I'm working on a website for work. I know minimal PHP, but I'm trying to set up a database with PHP+MySQL.

I'll spare you the details, but basically I need to sync the information on our site with the information on another site. This other site has a text file that can be accessed via FTP, and is updated periodically.

What I need to do, is read this file, and transfer the data to a database on our server.

All of that I can do. The problem now is WHEN do I do it? I don't want this sync to be triggered by user visits because that might cause conflicts when multiple users are visiting the site at the same time (there's no way I can make the sync atomic).

What I'm thinking is to have some kind of automated scheduling thing, where a php script is executed periodically (like every hour or something). That way the website itself only polls from my database -- and a separate process polls the FTP file and updates the database when necessary.

The only way I can think of to accomplish this would be to make a webpage that does the sync and refreshes itself every hour or so. Then I could leave that open in a browser all the time. But this solution seems very poor. Honestly any client-side solution seems poor. I'd really like this all to be done server side.

Does anyone have any better ideas?


Also -- does anyone have recommendations for PHP, or PHP/MySQL forums?

Thanks all!
Dec 10, 2010 at 10:52pm
Two questions,
1. Does this all have to be in PHP, or just the website?
2. Do you have access to the machine itself (can you run binary programs on it)?

You could write a program in C to run alongside the webserver (Apache or whatever you're using) that would do the sync.

As for a PHP forum, you can use http://www.php-forum.com/phpforum/
Dec 10, 2010 at 11:01pm
1. I'm limited to whatever our server is running. Right now I know it runs PHP and MySQL. It might also have CGI and Perl, but I know even less about them than I do about PHP, so I'd like to stick to PHP if possible.

2. No. C/C++ binaries are unfortunately not an option.

Right now I'm looking at this Cron thing which seems to be what I want. I'm in the middle of making a basic test to see if I can get it working.

I'll let you guys know if I'm successful.


Thanks for the help & for the forum recommendation.
Dec 10, 2010 at 11:11pm
Oh, crond. That might work. Here're the man pages if they're any help: http://linux.die.net/man/8/crond http://linux.die.net/man/5/crontab
Last edited on Dec 10, 2010 at 11:12pm
Dec 10, 2010 at 11:48pm
Yeah that's working. Just had to figure out how it worked with the way our server is set up.

Awesome!
Dec 10, 2010 at 11:53pm
Ok cool, so it works now?
Dec 11, 2010 at 12:37am
yeah works great.

Thanks
Topic archived. No new replies allowed.