PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/fuel/crons/ci_cron.php

https://github.com/chrisamoore/FUEL-CMS
PHP | 96 lines | 32 code | 18 blank | 46 comment | 5 complexity | 478144dff2950f22a50ad37d7e6750bb MD5 | raw file
  1. #!/usr/bin/php
  2. <?php
  3. /*
  4. |--------------------------------------------------------------
  5. | CRON JOB BOOTSTRAPPER
  6. |--------------------------------------------------------------
  7. |
  8. | By Jonathon Hill (http://jonathonhill.net)
  9. | CodeIgniter forum member "compwright" (http://codeigniter.com/forums/member/60942/)
  10. |
  11. | Created 08/19/2008
  12. | Version 1.2 (last updated 12/25/2008)
  13. |
  14. | Updated on 3/17/2011 By David McReynolds of Daylight Studio to fix CI 2.x issues
  15. |
  16. | PURPOSE
  17. | -------------------------------------------------------------
  18. | This script is designed to enable CodeIgniter controllers and functions to be easily called from the command line on UNIX/Linux systems.
  19. |
  20. |
  21. | SETUP
  22. | -------------------------------------------------------------
  23. | 1) Place this file somewhere outside your web server's document root
  24. | 2) Set the CRON_CI_INDEX constant to the location of your CodeIgniter index.php file
  25. | 3) Make this file executable (chmod a+x cron.php)
  26. | 4) You can then use this file to call any controller function:
  27. | ./cron.php controller/method
  28. |
  29. |
  30. | NOTE: Do not load any authentication or session libraries in controllers you want to run via cron. If you do, they probably won't run right.
  31. |
  32. |
  33. | Contributions:
  34. | -------------------------------------------------------------
  35. | "BDT" (http://codeigniter.com/forums/member/46597/) -- Fix for undefined constant CRON_FLUSH_BUFFERS error if the --show-output switch is not set (11/17/2008)
  36. | "electromute" (http://codeigniter.com/forums/member/71433/) -- Idea for [--server] commandline option (12/25/2008)
  37. |
  38. */
  39. define('CRON_CI_INDEX', '/var/www/httpdocs/index.php'); // Your CodeIgniter main index.php file
  40. define('CRON_LOG', '/var/www/httpdocs/fuel/application/logs/cron.log'); // path to the cron log file... MUST BE WRITABLE!
  41. define('CRON', TRUE); // Test for this in your controllers if you only want them accessible via cron
  42. define('CRON_FLUSH_BUFFERS', TRUE);
  43. define('CRON_TIME_LIMIT', 0);
  44. /*
  45. You may need to set the following $_SERVER variables in your index.php bootstrap at the top where it specifies "FUEL CLI (Command Line Interface)"
  46. $_SERVER['SERVER_NAME'] = 'localhost';
  47. $_SERVER['SERVER_PORT'] = 80;
  48. */
  49. # Parse the command line
  50. $script = array_shift($argv);
  51. $cmdline = implode(' ', $argv);
  52. $usage = "Usage: ci_cron.php URI_PATH\n\n";
  53. if (empty($argv))
  54. {
  55. die($usage);
  56. }
  57. $_SERVER['PATH_INFO'] = $argv[0];
  58. $_SERVER['REQUEST_URI'] = $argv[0];
  59. if(!defined('CRON_LOG')) define('CRON_LOG', 'cron.log');
  60. if(!defined('CRON_TIME_LIMIT')) define('CRON_TIME_LIMIT', 0);
  61. # Set run time limit
  62. set_time_limit(CRON_TIME_LIMIT);
  63. # Run CI and capture the output
  64. ob_start();
  65. chdir(dirname(CRON_CI_INDEX));
  66. require(CRON_CI_INDEX); // Main CI index.php file
  67. $output = ob_get_contents();
  68. if(defined('CRON_FLUSH_BUFFERS')) {
  69. while(@ob_end_flush()); // display buffer contents
  70. } else {
  71. ob_end_clean();
  72. }
  73. # Log the results of this run
  74. error_log("### ".date('Y-m-d H:i:s')." cron.php $cmdline\n", 3, CRON_LOG);
  75. error_log($output, 3, CRON_LOG);
  76. error_log("\n### \n\n", 3, CRON_LOG);
  77. echo "\n\n";
  78. ?>