PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > php cron to check and remove files
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
php cron to check and remove files

Réponse
 
LinkBack Outils de la discussion
Vieux 13/03/2008, 10h35   #1
Steven Macintyre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut php cron to check and remove files

Hi,

I need to be able to do the following procedure;

retrieve all items from a mysql db table, then check to see if the files from that table exist on the server (images), if not, to "clean up" and remove the physical file - so that only the files from the db exist.

This will run via cron

Has anyone done something similar before, willing to assist me with a basicscope of actions to work on?

Thanks in advance

Steven

  Réponse avec citation
Vieux 13/03/2008, 10h47   #2
Aschwin Wesselius
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] php cron to check and remove files

Steven Macintyre wrote:
> Hi,
>
> I need to be able to do the following procedure;
>
> retrieve all items from a mysql db table, then check to see if the files from that table exist on the server (images), if not, to "clean up" and remove the physical file - so that only the files from the db exist.
>
> This will run via cron
>
> Has anyone done something similar before, willing to assist me with a basic scope of actions to work on?


Hi,

Do you already have some code? Do you got stuck somewhere?

Aschwin Wesselius
  Réponse avec citation
Vieux 13/03/2008, 14h04   #3
Per Jessen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] php cron to check and remove files

Steven Macintyre wrote:

> retrieve all items from a mysql db table, then check to see if the
> files from that table exist on the server (images), if not, to "clean
> up" and remove the physical file - so that only the files from the db
> exist.


When you are comparing the contents of disk vs. db, you have three
possible outcomes:

1) file is listed in db, but not found on disk
2) file is found on disk, but not in db.
3) file is found on disk and in db.

I think I'd probably read the directories of where the physical files
are located into an array = files_in_disk(), then read in the file list
from the database into files_in_db(). Use array_diff() to identify the
discrepancies, then sort them out (delete file, add row, delete row).

for files_on_disk(), lookup opendir() and readdir().
for files_in_db(), lookup mysql_query() and mysql_fetch_assoc().

Will consume a lot of memory if you've got a lot of files.



/Per Jessen, Zürich

  Réponse avec citation
Vieux 13/03/2008, 16h45   #4
Al
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php cron to check and remove files

I handle your object a different and, I believe, a simpler way.

Instead of a cronjob, I call a cleanup function whenever a page is opened.

Obviously, this approach requires a time overhead and thus is not good for very
high volume sites. You can mitigate this drawback by maintaining a simple
touch() file that keeps track of the time when your cleanup function is run and
insure it only runs once a day, or whatever frequency you need. You can even
make the file sticky so it stays in memory to further reduce the overhead.



Steven Macintyre wrote:
> Hi,
>
> I need to be able to do the following procedure;
>
> retrieve all items from a mysql db table, then check to see if the files from that table exist on the server (images), if not, to "clean up" and remove the physical file - so that only the files from the db exist.
>
> This will run via cron
>
> Has anyone done something similar before, willing to assist me with a basic scope of actions to work on?
>
> Thanks in advance
>
> Steven
>

  Réponse avec citation
Vieux 13/03/2008, 17h21   #5
tedd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] php cron to check and remove files

At 9:35 AM +0100 3/13/08, Steven Macintyre wrote:
> Hi,
>
>I need to be able to do the following procedure;
>
>retrieve all items from a mysql db table, then check to see if the
>files from that table exist on the server (images), if not, to
>"clean up" and remove the physical file - so that only the files
>from the db exist.
>
>This will run via cron
>
>Has anyone done something similar before, willing to assist me with
>a basic scope of actions to work on?
>
>Thanks in advance
>
>Steven



Steven:

Are you saying that if images exist in your database AND appear in
the file system, then don't delete them?

Why not give your approved images a prefix and just delete everything
that doesn't via a cron?

Cheers,

tedd


--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
  Réponse avec citation
Vieux 13/03/2008, 17h57   #6
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php cron to check and remove files

Steven Macintyre wrote:
> Hi,
>
> I need to be able to do the following procedure;
>
> retrieve all items from a mysql db table, then check to see if the files from that table exist on the server (images), if not, to "clean up" and remove the physical file - so that only the files from the db exist.
>
> This will run via cron
>
> Has anyone done something similar before, willing to assist me with a basic scope of actions to work on?
>
> Thanks in advance
>
> Steven
>


Maybe a dumb question, but after truing up the db and fs, why not delete
the file when you delete from the db?

-Shawn
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h19.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16602 seconds with 14 queries