From 68cb074c6aece594521b4508b09fbc02fc41d7f1 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 26 Dec 2013 10:55:36 -0500 Subject: [PATCH] Fixed #1504: Debug toolbar isn't loaded successfully in some environments when xdebug is enabled --- extensions/yii/debug/CHANGELOG.md | 2 +- .../yii/debug/controllers/DefaultController.php | 45 +++++++++++++--------- framework/CHANGELOG.md | 1 + 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/extensions/yii/debug/CHANGELOG.md b/extensions/yii/debug/CHANGELOG.md index 1f83ca4..21bbcfa 100644 --- a/extensions/yii/debug/CHANGELOG.md +++ b/extensions/yii/debug/CHANGELOG.md @@ -4,7 +4,7 @@ Yii Framework 2 debug extension Change Log 2.0.0 beta under development ---------------------------- -- no changes in this release. +- Bug #1504: Debug toolbar isn't loaded successfully in some environments when xdebug is enabled (qiangxue) 2.0.0 alpha, December 1, 2013 ----------------------------- diff --git a/extensions/yii/debug/controllers/DefaultController.php b/extensions/yii/debug/controllers/DefaultController.php index 0c8d6e9..5c3c444 100644 --- a/extensions/yii/debug/controllers/DefaultController.php +++ b/extensions/yii/debug/controllers/DefaultController.php @@ -64,7 +64,7 @@ class DefaultController extends Controller public function actionToolbar($tag) { - $this->loadData($tag); + $this->loadData($tag, 3); return $this->renderPartial('toolbar', [ 'tag' => $tag, 'panels' => $this->module->panels, @@ -78,9 +78,12 @@ class DefaultController extends Controller private $_manifest; - protected function getManifest() + protected function getManifest($forceReload = false) { - if ($this->_manifest === null) { + if ($this->_manifest === null || $forceReload) { + if ($forceReload) { + clearstatcache(); + } $indexFile = $this->module->dataPath . '/index.data'; if (is_file($indexFile)) { $this->_manifest = array_reverse(unserialize(file_get_contents($indexFile)), true); @@ -91,24 +94,30 @@ class DefaultController extends Controller return $this->_manifest; } - public function loadData($tag) + public function loadData($tag, $maxRetry = 0) { - $manifest = $this->getManifest(); - if (isset($manifest[$tag])) { - $dataFile = $this->module->dataPath . "/$tag.data"; - $data = unserialize(file_get_contents($dataFile)); - foreach ($this->module->panels as $id => $panel) { - if (isset($data[$id])) { - $panel->tag = $tag; - $panel->load($data[$id]); - } else { - // remove the panel since it has not received any data - unset($this->module->panels[$id]); + // retry loading debug data because the debug data is logged in shutdown function + // which may be delayed in some environment if xdebug is enabled. + // See: https://github.com/yiisoft/yii2/issues/1504 + for ($retry = 0; $retry <= $maxRetry; ++$retry) { + $manifest = $this->getManifest($retry > 0); + if (isset($manifest[$tag])) { + $dataFile = $this->module->dataPath . "/$tag.data"; + $data = unserialize(file_get_contents($dataFile)); + foreach ($this->module->panels as $id => $panel) { + if (isset($data[$id])) { + $panel->tag = $tag; + $panel->load($data[$id]); + } else { + // remove the panel since it has not received any data + unset($this->module->panels[$id]); + } } + $this->summary = $data['summary']; + return; } - $this->summary = $data['summary']; - } else { - throw new NotFoundHttpException("Unable to find debug data tagged with '$tag'."); } + + throw new NotFoundHttpException("Unable to find debug data tagged with '$tag'."); } } diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index ce15891..e8e324b 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -7,6 +7,7 @@ Yii Framework 2 Change Log - Bug #1446: Logging while logs are processed causes infinite loop (qiangxue) - Bug #1497: Localized view files are not correctly returned (mintao) - Bug #1500: Log messages exported to files are not separated by newlines (omnilight, qiangxue) +- Bug #1504: Debug toolbar isn't loaded successfully in some environments when xdebug is enabled (qiangxue) - Bug #1509: The SQL for creating Postgres RBAC tables is incorrect (qiangxue) - Bug #1545: It was not possible to execute db Query twice, params where missing (cebe) - Bug #1550: fixed the issue that JUI input widgets did not property input IDs.