mercoledì 27 gennaio 2010

UNICAL_INFO - Eseguire script PHP ad intervalli regolari di tempo















Eseguire script PHP ad
intervalli regolari di tempo

Data: Wednesday, 31 July @ 17:44:47
CEST
Argomento:
webproject



Running PHP scripts as cronjobs


(...)
The first dilema depends on your PHP
installation:



  • Compiled CGI
  • Apache module

Compiled CGI
In the first case you'll have to
add a line to your script. It must the first line of your
script and must contain PHP executable location:


#!/usr/local/bin/php -q


After that let's add the necessary command to our
crontab. Edit /etc/crontab (or wherever your crontab file is)
and add the following line:


* * * * *
php /path/to/your/cron.php


execute the following from the command line:


Shell>
crontab crontab


Be
sure cron.php has the necessary permissions to be
executable.


Apache module

If you have PHP
installed as an Apache module the approach is quite
different.

First of
all you need access to lynx (read here for
more information).
You PHP script does not need additional
lines in this case. You simply have to edit your /etc/crontab
file and add the following line:


* * * * *
lynx -dump http://www.somedomain.com/cron.php


Note you generally have to specify the compete URL:
depending on your lynx configuration the URL should be
relative but I suggest to always use the absolute reference
like in the example above, since it always works.


Again execute the following from the command
line:


Shell>
crontab crontab
(...)



in pratica noi
l'abbiamo applicato così, usando, in
telnet
/usr/bin/crontab -e
per esguire, ogni 5 minuti,
un file
php
###############################################################
MAILTO=""
*/5
* * * * lynx -dump
http://dominio/path_del_file/file.php
###############################################################
con
MAILTO="" per non ricevere ogni cinque minuti una mail col
dump prodotto dal file php


Cosa fa il nostro file php?



  • controlla la posta di reporter@elinux.economia.unical.it

  • per ogni nuovo messaggio

    • se è presente un allegato

      • lo decodifica
      • lo salva in una cartella
      • aggiunge un record al database MySQL del portale per
        scrivere un nuovo articolo con i dati ricavati dal
        messaggio
      • elimina il messaggio elaborato

    • se non è presente un allegato

      • elimina il messaggio

 








Questo Articolo proviene da UNICAL.INFO
http://elinux.economia.unical.it/

L'URL
per questa storia �:
http://elinux.economia.unical.it/modules.php?name=News&file=article&sid=118

Nessun commento: