How to create cron job using PHP? -


i'm new using cron job. don't know how write it. have tried search internet, still don't understand well. want create cron job execute code every minute. i'm using php create it. not working.

example

run.php (code executed every minute)

<?php  echo "this code run every minute";  ?> 

cron.php

<?php  $path = dirname(__file__); $cron = $path . "/run.php"; echo exec("***** php -q ".$cron." &> /dev/null");  ?> 

suppose these 2 files in same folder.

is code did wrong? if wrong, please kindly tell me how fix it.

this best explanation code in php have found far:

http://code.tutsplus.com/tutorials/managing-cron-jobs-with-php--net-19428

in short:

although syntax of scheduling new job may seem daunting @ first glance, it's relatively simple understand once break down. cron job have 5 columns each of represent chronological 'operator' followed full path , command execute:

* * * * * home/path/to/command/the_command.sh

each of chronological columns has specific relevance schedule of task. follows:

minutes represents minutes of given hour, 0-59 respectively. hours represents hours of given day, 0-23 respectively. days represents days of given month, 1-31 respectively. months represents months of given year, 1-12 respectively. day of week represents day of week, sunday through saturday, numerically, 0-6 respectively. 

enter image description here

so, example, if 1 wanted schedule task 12am on first day of every month this:

0 0 1 * * home/path/to/command/the_command.sh

if wanted schedule task run every saturday @ 8:30am we'd write follows:

30 8 * * 6 home/path/to/command/the_command.sh

there number of operators can used customize schedule further:

commas used create comma separated list of values of cron columns. dashes used specify range of values. asterisksis used specify 'all' or 'every' value 

visit link full article, explains:

  1. what format of cronjob if want enter/edit manually.
  2. how use php ssh2 library authenticate user, crontab going edit.
  3. full php class necessary methods authentication, editing , deleting crontab entries.

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -