display_cache_content.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. return;
  43. }
  44. $sKey = $aEntries[0];
  45. $result = apc_fetch($sKey);
  46. if (!is_object($result))
  47. {
  48. return;
  49. }
  50. $oSQLQuery = $result;
  51. echo "NB Tables before;NB Tables after;";
  52. foreach($oSQLQuery->m_aContextData as $sField => $oValue)
  53. {
  54. echo $sField.';';
  55. }
  56. echo "\n";
  57. sort($aEntries);
  58. foreach($aEntries as $sKey)
  59. {
  60. $result = apc_fetch($sKey);
  61. if (is_object($result))
  62. {
  63. $oSQLQuery = $result;
  64. if (isset($oSQLQuery->m_aContextData))
  65. {
  66. echo $oSQLQuery->m_iOriginalTableCount.";".$oSQLQuery->CountTables().';';
  67. foreach($oSQLQuery->m_aContextData as $oValue)
  68. {
  69. if (is_array($oValue))
  70. {
  71. $sVal = json_encode($oValue);
  72. }
  73. else
  74. {
  75. if (empty($oValue))
  76. {
  77. $sVal = '';
  78. }
  79. else
  80. {
  81. $sVal = $oValue;
  82. }
  83. }
  84. echo $sVal.';';
  85. }
  86. echo "\n";
  87. }
  88. }
  89. }
  90. echo "</pre>";