EPESI BIM • Business Information Manager • Cloud CRM/ERP http://epe.si/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

109 lines
3.6 KiB

  1. <?php
  2. /**
  3. * This file provides monitoring functionality...
  4. * Returns time of execution in ms
  5. * Available arguments: number (if defined and true script will return 999999 on any error), type (session, database, data_directory - run only one test)
  6. * @author Paul Bukowski <pbukowski@telaxus.com>
  7. * @copyright Copyright &copy; 2006, Telaxus LLC
  8. * @license MIT
  9. * @version 1.0
  10. * @package epesi-base
  11. */
  12. define('CID',1);
  13. define('SET_SESSION',false);
  14. if (php_sapi_name() == 'cli') {
  15. define('EPESI_DIR', '/');
  16. if (isset($argv[1])) {
  17. define('DATA_DIR', $argv[1]);
  18. }
  19. } elseif (!isset($_GET['token'])) {
  20. die('Missing token in URL - please go to Administrator Panel->Cron and copy valid cron URL.');
  21. } else {
  22. defined("_VALID_ACCESS") || define("_VALID_ACCESS", true);
  23. require_once('include/include_path.php');
  24. require_once('include/data_dir.php');
  25. if(!file_exists(DATA_DIR.'/cron_token.php'))
  26. die('Invalid token in URL - please go to Administrator Panel->Cron and copy valid cron URL.');
  27. require_once(DATA_DIR.'/cron_token.php');
  28. if(CRON_TOKEN!=$_GET['token'])
  29. die('Invalid token in URL - please go to Administrator Panel->Cron and copy valid cron URL.');
  30. }
  31. try {
  32. require_once('include.php');
  33. ModuleManager::load_modules();
  34. Base_AclCommon::set_sa_user();
  35. } catch(Exception $e) {
  36. if(isset($_GET['number']) && $_GET['number']) die('999999');
  37. die('error: init');
  38. }
  39. class MonitoringErrorObserver extends ErrorObserver {
  40. public function update_observer($type, $message,$errfile,$errline,$errcontext, $backtrace) {
  41. if(isset($_GET['number']) && $_GET['number']) die('999999');
  42. die('error: '.$type.'# '.$message);
  43. }
  44. }
  45. $err = new MonitoringErrorObserver();
  46. ErrorHandler::add_observer($err);
  47. function test_database() {
  48. $up = epesi_requires_update();
  49. if($up===null) {
  50. if(isset($_GET['number']) && $_GET['number']) die('999999');
  51. die('error: database');
  52. } elseif($up===true) {
  53. if(isset($_GET['number']) && $_GET['number']) die('999999');
  54. die('error: version');
  55. }
  56. }
  57. function test_session() {
  58. $tag = microtime(1);
  59. $session_id = 'monitoring_'.md5(DATABASE_NAME.'#'.DATABASE_HOST.'#'.DATABASE_DRIVER);
  60. $_SESSION = EpesiSession::get($session_id);
  61. $_SESSION['monitoring'] = $tag;
  62. $_SESSION['client']['monitoring'] = $tag;
  63. EpesiSession::set($session_id, $_SESSION);
  64. $_SESSION = EpesiSession::get($session_id);
  65. if(!isset($_SESSION['monitoring']) || !isset($_SESSION['client']['monitoring']) || $_SESSION['monitoring'] != $tag || $_SESSION['client']['monitoring'] != $tag) {
  66. EpesiSession::set($session_id, $_SESSION);
  67. if(isset($_GET['number']) && $_GET['number']) die('999999');
  68. die('error: session');
  69. }
  70. EpesiSession::set($session_id, $_SESSION);
  71. }
  72. function test_data_directory() {
  73. $tag = (string)microtime(1);
  74. if(!is_writable(DATA_DIR)) {
  75. if(isset($_GET['number']) && $_GET['number']) die('999999');
  76. die('error: data directory now writable');
  77. }
  78. $test_file = DATA_DIR.'/monitoring_test_file.txt';
  79. @file_put_contents($test_file, $tag);
  80. if(@file_get_contents($test_file) != $tag) {
  81. if(isset($_GET['number']) && $_GET['number']) die('999999');
  82. die('error: data directory write/read error');
  83. }
  84. unlink($test_file);
  85. }
  86. $t = microtime(1);
  87. if(isset($_GET['type'])) {
  88. if(in_array($_GET['type'],array('database','session','data_directory'))) {
  89. call_user_func('test_'.$_GET['type']);
  90. } else {
  91. die('Invalid test type: '.$_GET['type']);
  92. }
  93. } else {
  94. test_database();
  95. test_session();
  96. test_data_directory();
  97. }
  98. die(round((microtime(1)-$t)*1000));