display_cache_content.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // Copyright (c) 2010-2017 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. //
  19. /**
  20. * Date: 06/10/2017
  21. */
  22. require_once('../approot.inc.php');
  23. require_once(APPROOT.'application/startup.inc.php');
  24. $sEnvironment = MetaModel::GetEnvironmentId();
  25. $aEntries = array();
  26. $aCacheUserData = apc_cache_info_compat();
  27. if (is_array($aCacheUserData) && isset($aCacheUserData['cache_list']))
  28. {
  29. $sPrefix = 'itop-'.$sEnvironment.'-query-cache-';
  30. foreach($aCacheUserData['cache_list'] as $i => $aEntry)
  31. {
  32. $sEntryKey = array_key_exists('info', $aEntry) ? $aEntry['info'] : $aEntry['key'];
  33. if (strpos($sEntryKey, $sPrefix) === 0)
  34. {
  35. $aEntries[] = $sEntryKey;
  36. }
  37. }
  38. }
  39. echo "<pre>";
  40. if (empty($aEntries))
  41. {
  42. echo "No Data";
  43. return;
  44. }
  45. $sKey = $aEntries[0];
  46. $result = apc_fetch($sKey);
  47. if (!is_object($result))
  48. {
  49. return;
  50. }
  51. $oSQLQuery = $result;
  52. echo "NB Tables before;NB Tables after;";
  53. foreach($oSQLQuery->m_aContextData as $sField => $oValue)
  54. {
  55. echo $sField.';';
  56. }
  57. echo "\n";
  58. sort($aEntries);
  59. foreach($aEntries as $sKey)
  60. {
  61. $result = apc_fetch($sKey);
  62. if (is_object($result))
  63. {
  64. $oSQLQuery = $result;
  65. if (isset($oSQLQuery->m_aContextData))
  66. {
  67. echo $oSQLQuery->m_iOriginalTableCount.";".$oSQLQuery->CountTables().';';
  68. foreach($oSQLQuery->m_aContextData as $oValue)
  69. {
  70. if (is_array($oValue))
  71. {
  72. $sVal = json_encode($oValue);
  73. }
  74. else
  75. {
  76. if (empty($oValue))
  77. {
  78. $sVal = '';
  79. }
  80. else
  81. {
  82. $sVal = $oValue;
  83. }
  84. }
  85. echo $sVal.';';
  86. }
  87. echo "\n";
  88. }
  89. }
  90. }
  91. echo "</pre>";