View Full Version : Automatic database updation based on files in a directory?
I am new to mysql and using phpMyadmin with XAMPP. I am trying to synchronize a database with a directory on my computer. The database must contain the names of the files contained within that particular directory.
Moreover when I add files to that directory, the database should update automatically with the name of the new file. Is this possible. Any hints on how to go about this. Please help me guys...
abduraooft
08-10-2009, 09:15 AM
You could write a cron job to scan your directory at specified intervals and get the required task done.
I am new to php and mysql and might need more help than that :(
but I would understand if you cant elaborate... thanks for giving me direction though...
Old Pedant
08-11-2009, 01:10 AM
A "cron job" simply means a task that is executed at a specifed time. The name is used because "cron" is the Linux command-line command that does such scheduling.
The problem is that a "cron job" must be an executable command. Which means you normally would *NOT* write it in PHP.
If you only know PHP programming, then I think a better way to do this would be to just use PHP code to make a quick directory scan on an "as needed" basis. If it's not a very large directory, and if you only scanned it (say) once per user login, that wouldn't be too much overhead.
djm0219
08-11-2009, 03:44 AM
The problem is that a "cron job" must be an executable command. Which means you normally would *NOT* write it in PHP.
No reason at all not to use PHP for cron jobs. Many a production job is run by a series of cron jobs which are all done with PHP :)
Old Pedant
08-11-2009, 07:31 AM
So how do you invoke the PHP page from cron???
By invoking a browser for it to run in?
Curiosity only on my part; important info for original poster on his part.
abduraooft
08-11-2009, 09:45 AM
Curiosity only on my part; important info for original poster on his part. See http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/
djm0219
08-11-2009, 12:34 PM
So how do you invoke the PHP page from cron??
The link abduraooft explains it quite well. You essentially use the command line version of PHP to run things from cron. No browser needed and, in most cases, the code resides outside of the web root directory so a browser can't even get it.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.