How can I write a PHP cron script?

后端 未结 3 810
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 09:04

I\'m sorry if this is a silly question, but in reality I have no clue.

I wrote this app to compress and move files from a client\'s PC to a master PC.
It works

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-07 09:38

    To add a cronjob in linux do this:

    # crontab -e if vi is your editor press i to enter text and esc to exit. Use :w to save your changes and :q to quit. If nano is your choosen editor, then use strg+o for saving and str+x for closing.

    Anyway add this line to the bodom of the file: */5 * * * * php runScript.php

    It will be called every 5min.

    * * * * * php /path/to/file/runScript.php
    ┬ ┬ ┬ ┬ ┬
    │ │ │ │ │
    │ │ │ │ └──── Day of the week (0-7, Sunday is 0 or 7)
    │ │ │ └────── Month (1-12)
    │ │ └──────── Day (1-31)
    │ └────────── Hour (0-23)
    └──────────── Minute (0-59) 
    

    That should be it :)

提交回复
热议问题