0

Pardon me if a very relevant question is already asked. I am working on a PHP project (small level) where I need to execute a PHP file (MySQL related tasks) every minute. I can make it work by manually setting up the cron job to execute this file but I want to keep things simple for my project's end users by automatically adding the cron task when script is first run. Can anyone please help me in the right direction? Complete code example will be appreciated.

Rehmat
  • 3,732
  • 1
  • 16
  • 32
  • 5
    http://stackoverflow.com/q/4421020/697370 – Jeff Lambert May 06 '16 at 15:02
  • That's behaviour I would expect from malware, not from a regular application. I would consider rethinking the strategy. – Sumurai8 May 06 '16 at 15:03
  • @Sumurai8 Thank you for your comment. But actually it is an website uptime monitoring application for that the script needs to check the target URL every x minutes based on the user choice. To make the things simple for common users, I'm thinking to apply this strategy in my script. – Rehmat May 06 '16 at 15:05
  • @JeffLambert Thank you for mentioning the link. I'm trying to get what the best (accepted) answering is saying there. – Rehmat May 06 '16 at 15:12

1 Answers1

0

To execute a file every minute using cron, you can use:

* * * * * /path/to/php /var/www/html/script.php

Or simply:

* * * * * php /var/www/html/script.php

if PHP is already included on your PATH environmental variable

Pedro Lobito
  • 75,541
  • 25
  • 200
  • 222