public function bench(RestServer $rest) { $rest->getResponse()->appendResponse("It took " . round(xdebug_time_index(), 5) . " seconds\n"); $rest->getResponse()->appendResponse("Used " . round(xdebug_memory_usage() / 1024, 5) . "Kb of Memory\n"); $rest->getResponse()->appendResponse("Used at peak " . round(xdebug_peak_memory_usage() / 1024, 5) . "Kb of Memory\n"); return $rest; }
public function paintFooter($test_name) { if (function_exists('xdebug_peak_memory_usage')) { $max_mem = number_format(xdebug_peak_memory_usage()); echo "<div>Max memory usage: {$max_mem} bytes</div>"; } parent::paintFooter($test_name); }
/** * @param \Civi\API\Event\RespondEvent $event * API response event. */ public function onApiRespond(\Civi\API\Event\RespondEvent $event) { $apiRequest = $event->getApiRequest(); $result = $event->getResponse(); if (function_exists('xdebug_time_index') && \CRM_Utils_Array::value('debug', $apiRequest['params']) && is_array($result)) { $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage(); $result['xdebug']['memory'] = xdebug_memory_usage(); $result['xdebug']['timeIndex'] = xdebug_time_index(); $event->setResponse($result); } }
// } else { // $controller->execute(JRequest::getCmd('task', '')); // } $controller->execute(JRequest::getCmd('task', '')); $jConfig =& JFactory::getConfig(); // Some hosting providers has xdebug installed for debugging purposes. We really shouldn't show this // on live site unless they turn on debugging mode. if (function_exists('xdebug_memory_usage') && $jConfig->getValue('debug')) { $memNow = xdebug_memory_usage(); $db = JFactory::getDBO(); $db->debug(1); echo '<div style="clear:both"> </div><pre>'; echo 'Start usage : ' . cConvertMem($mem) . '<br/>'; echo 'End usage : ' . cConvertMem($memNow) . '<br/>'; echo 'Mem usage : ' . cConvertMem($memNow - $mem) . '<br/>'; echo 'Peak mem : ' . cConvertMem(xdebug_peak_memory_usage()) . '<br/>'; echo 'Time : ' . (xdebug_time_index() - $tm) . '<br/>'; echo 'Query : ' . $db->getTicker(); echo '</pre>'; // Log average page load jimport('joomla.filesystem.file'); $content = JFile::read(COMMUNITY_COM_PATH . DS . 'access.log'); $params = new JParameter($content); $today = strftime('%Y-%m-%d'); $loadTime = $params->get($today, 0); if ($loadTime > 0) { $loadTime = ($loadTime + (xdebug_time_index() - $tm)) / 2; } else { $loadTime = xdebug_time_index() - $tm; } $params->set($today, $loadTime);
/** * add ILIAS footer */ function addILIASFooter() { global $ilAuth; if (!$this->getAddFooter()) { return; } global $ilias, $ilClientIniFile, $ilCtrl, $ilDB, $ilSetting, $lng; $ftpl = new ilTemplate("tpl.footer.html", true, true, "Services/UICore"); $ftpl->setVariable("ILIAS_VERSION", $ilias->getSetting("ilias_version")); $link_items = array(); // imprint include_once "Services/Imprint/classes/class.ilImprint.php"; if ($_REQUEST["baseClass"] != "ilImprintGUI" && ilImprint::isActive()) { include_once "Services/Link/classes/class.ilLink.php"; $link_items[ilLink::_getStaticLink(0, "impr")] = array($lng->txt("imprint"), true); } $link_items["mailto:" . ilUtil::prepareFormOutput($ilSetting->get("feedback_recipient"))] = array($lng->txt("contact_sysadmin"), false); if (DEVMODE && version_compare(PHP_VERSION, '5', '>=')) { $link_items[ilUtil::appendUrlParameterString($_SERVER["REQUEST_URI"], "do_dev_validate=xhtml")] = array("Validate", true); $link_items[ilUtil::appendUrlParameterString($_SERVER["REQUEST_URI"], "do_dev_validate=accessibility")] = array("Accessibility", true); } // output translation link (extended language maintenance) if ($ilSetting->get("lang_ext_maintenance") == "1") { include_once "Services/Language/classes/class.ilObjLanguageAccess.php"; if (ilObjLanguageAccess::_checkTranslate() and !ilObjLanguageAccess::_isPageTranslation()) { ilObjLanguageAccess::_saveUsages(); $link_items[ilObjLanguageAccess::_getTranslationLink()] = array($lng->txt('translation'), true); } } $cnt = 0; foreach ($link_items as $url => $caption) { $cnt++; if ($caption[1]) { $ftpl->touchBlock("blank"); } if ($cnt < sizeof($link_items)) { $ftpl->touchBlock("item_separator"); } $ftpl->setCurrentBlock("items"); $ftpl->setVariable("URL_ITEM", $url); $ftpl->setVariable("TXT_ITEM", $caption[0]); $ftpl->parseCurrentBlock(); } if (DEVMODE) { // execution time $t1 = explode(" ", $GLOBALS['ilGlobalStartTime']); $t2 = explode(" ", microtime()); $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1]; $mem_usage = array(); if (function_exists("memory_get_usage")) { $mem_usage[] = "Memory Usage: " . memory_get_usage() . " Bytes"; } if (function_exists("xdebug_peak_memory_usage")) { $mem_usage[] = "XDebug Peak Memory Usage: " . xdebug_peak_memory_usage() . " Bytes"; } $mem_usage[] = round($diff, 4) . " Seconds"; if (sizeof($mem_usage)) { $ftpl->setVariable("MEMORY_USAGE", "<br>" . implode(" | ", $mem_usage)); } if (is_object($ilAuth) && isset($_SESSION[$ilAuth->_sessionName]) && isset($_SESSION[$ilAuth->_sessionName]["timestamp"])) { $ftpl->setVariable("SESS_INFO", "<br />maxlifetime: " . ini_get("session.gc_maxlifetime") . " (" . ini_get("session.gc_maxlifetime") / 60 . "), id: " . session_id() . "<br />" . "timestamp: " . date("Y-m-d H:i:s", $_SESSION[$ilAuth->_sessionName]["timestamp"]) . ", idle: " . date("Y-m-d H:i:s", $_SESSION[$ilAuth->_sessionName]["idle"]) . "<br />expire: " . ($exp = $ilClientIniFile->readVariable("session", "expire")) . " (" . $exp / 60 . "), session ends at: " . date("Y-m-d H:i:s", $_SESSION[$ilAuth->_sessionName]["idle"] + $exp)); } if (!empty($_GET["do_dev_validate"]) && $ftpl->blockExists("xhtml_validation")) { require_once "Services/XHTMLValidator/classes/class.ilValidatorAdapter.php"; $template2 = clone $this; //echo "-".ilValidatorAdapter::validate($template2->get(), $_GET["do_dev_validate"])."-"; $ftpl->setCurrentBlock("xhtml_validation"); $ftpl->setVariable("VALIDATION", ilValidatorAdapter::validate($template2->get("DEFAULT", false, false, false, true), $_GET["do_dev_validate"])); $ftpl->parseCurrentBlock(); } // controller history if (is_object($ilCtrl) && $ftpl->blockExists("c_entry") && $ftpl->blockExists("call_history")) { $hist = $ilCtrl->getCallHistory(); foreach ($hist as $entry) { $ftpl->setCurrentBlock("c_entry"); $ftpl->setVariable("C_ENTRY", $entry["class"]); if (is_object($ilDB)) { $file = $ilCtrl->lookupClassPath($entry["class"]); $add = $entry["mode"] . " - " . $entry["cmd"]; if ($file != "") { $add .= " - " . $file; } $ftpl->setVariable("C_FILE", $add); } $ftpl->parseCurrentBlock(); } $ftpl->setCurrentBlock("call_history"); $ftpl->parseCurrentBlock(); // debug hack $debug = $ilCtrl->getDebug(); foreach ($debug as $d) { $ftpl->setCurrentBlock("c_entry"); $ftpl->setVariable("C_ENTRY", $d); $ftpl->parseCurrentBlock(); } $ftpl->setCurrentBlock("call_history"); $ftpl->parseCurrentBlock(); } // included files if (is_object($ilCtrl) && $ftpl->blockExists("i_entry") && $ftpl->blockExists("included_files")) { $fs = get_included_files(); $ifiles = array(); $total = 0; foreach ($fs as $f) { $ifiles[] = array("file" => $f, "size" => filesize($f)); $total += filesize($f); } $ifiles = ilUtil::sortArray($ifiles, "size", "desc", true); foreach ($ifiles as $f) { $ftpl->setCurrentBlock("i_entry"); $ftpl->setVariable("I_ENTRY", $f["file"] . " (" . $f["size"] . " Bytes, " . round(100 / $total * $f["size"], 2) . "%)"); $ftpl->parseCurrentBlock(); } $ftpl->setCurrentBlock("i_entry"); $ftpl->setVariable("I_ENTRY", "Total (" . $total . " Bytes, 100%)"); $ftpl->parseCurrentBlock(); $ftpl->setCurrentBlock("included_files"); $ftpl->parseCurrentBlock(); } } // BEGIN Usability: Non-Delos Skins can display the elapsed time in the footer // The corresponding $ilBench->start invocation is in inc.header.php global $ilBench; $ilBench->stop("Core", "ElapsedTimeUntilFooter"); $ftpl->setVariable("ELAPSED_TIME", ", " . number_format($ilBench->getMeasuredTime("Core", "ElapsedTimeUntilFooter"), 1) . ' seconds'); // END Usability: Non-Delos Skins can display the elapsed time in the footer $this->setVariable("FOOTER", $ftpl->get()); }
<p><?php echo ActiveSupport\DateHelper::to_string('db', time()); ?> </p> <p><?php echo ActiveSupport\DateHelper::to_string('rfc822', time()); ?> </p> <p><?php echo ActiveSupport\TimeHelper::to_string('db', time()); ?> </p> <p><?php echo ActiveSupport\TimeHelper::to_string('rfc822', time()); ?> </p> <p>Memory usage: <?php echo xdebug_memory_usage() / 1024 / 1024; ?> </p> <p>Peak Memory usage: <?php echo xdebug_peak_memory_usage() / 1024 / 1024; ?> </p> <p>Execution Time: <?php echo xdebug_time_index(); ?> </p>
/** * @param string $entity * type of entities to deal with * @param string $action * create, get, delete or some special action name. * @param array $params * array to be passed to function * @param null $extra * * @return array|int */ function civicrm_api($entity, $action, $params, $extra = NULL) { $apiRequest = array(); $apiRequest['entity'] = CRM_Utils_String::munge($entity); $apiRequest['action'] = CRM_Utils_String::munge($action); $apiRequest['version'] = civicrm_get_api_version($params); $apiRequest['params'] = $params; $apiRequest['extra'] = $extra; $apiWrappers = array(CRM_Utils_API_HTMLInputCoder::singleton(), CRM_Utils_API_NullOutputCoder::singleton(), CRM_Utils_API_ReloadOption::singleton(), CRM_Utils_API_MatchOption::singleton()); CRM_Utils_Hook::apiWrappers($apiWrappers, $apiRequest); try { require_once 'api/v3/utils.php'; require_once 'api/Exception.php'; if (!is_array($params)) { throw new API_Exception('Input variable `params` is not an array', 2000); } _civicrm_api3_initialize(); $errorScope = CRM_Core_TemporaryErrorScope::useException(); // look up function, file, is_generic $apiRequest += _civicrm_api_resolve($apiRequest); if (strtolower($action) == 'create' || strtolower($action) == 'delete' || strtolower($action) == 'submit') { $apiRequest['is_transactional'] = 1; $transaction = new CRM_Core_Transaction(); } // support multi-lingual requests if ($language = CRM_Utils_Array::value('option.language', $params)) { _civicrm_api_set_locale($language); } _civicrm_api3_api_check_permission($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']); $fields = _civicrm_api3_api_getfields($apiRequest); // we do this before we _civicrm_api3_swap_out_aliases($apiRequest, $fields); if (strtolower($action) != 'getfields') { if (empty($apiRequest['params']['id'])) { $apiRequest['params'] = array_merge(_civicrm_api3_getdefaults($apiRequest, $fields), $apiRequest['params']); } //if 'id' is set then only 'version' will be checked but should still be checked for consistency civicrm_api3_verify_mandatory($apiRequest['params'], NULL, _civicrm_api3_getrequired($apiRequest, $fields)); } // For input filtering, process $apiWrappers in forward order foreach ($apiWrappers as $apiWrapper) { $apiRequest = $apiWrapper->fromApiInput($apiRequest); } $function = $apiRequest['function']; if ($apiRequest['function'] && $apiRequest['is_generic']) { // Unlike normal API implementations, generic implementations require explicit // knowledge of the entity and action (as well as $params). Bundle up these bits // into a convenient data structure. $result = $function($apiRequest); } elseif ($apiRequest['function'] && !$apiRequest['is_generic']) { _civicrm_api3_validate_fields($apiRequest['entity'], $apiRequest['action'], $apiRequest['params'], $fields); $result = isset($extra) ? $function($apiRequest['params'], $extra) : $function($apiRequest['params']); } else { return civicrm_api3_create_error("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)"); } // For output filtering, process $apiWrappers in reverse order foreach (array_reverse($apiWrappers) as $apiWrapper) { $result = $apiWrapper->toApiOutput($apiRequest, $result); } if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { if ($result['is_error'] === 0) { return 1; } else { return 0; } } if (!empty($apiRequest['params']['format.only_id']) && isset($result['id'])) { return $result['id']; } if (CRM_Utils_Array::value('is_error', $result, 0) == 0) { _civicrm_api_call_nested_api($apiRequest['params'], $result, $apiRequest['action'], $apiRequest['entity'], $apiRequest['version']); } if (function_exists('xdebug_time_index') && CRM_Utils_Array::value('debug', $apiRequest['params']) && is_array($result)) { $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage(); $result['xdebug']['memory'] = xdebug_memory_usage(); $result['xdebug']['timeIndex'] = xdebug_time_index(); } return $result; } catch (PEAR_Exception $e) { if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { return 0; } $error = $e->getCause(); if ($error instanceof DB_Error) { $data["error_code"] = DB::errorMessage($error->getCode()); $data["sql"] = $error->getDebugInfo(); } if (!empty($apiRequest['params']['debug'])) { if (method_exists($e, 'getUserInfo')) { $data['debug_info'] = $error->getUserInfo(); } if (method_exists($e, 'getExtraData')) { $data['debug_info'] = $data + $error->getExtraData(); } $data['trace'] = $e->getTraceAsString(); } else { $data['tip'] = "add debug=1 to your API call to have more info about the error"; } $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest); if (!empty($apiRequest['is_transactional'])) { $transaction->rollback(); } return $err; } catch (API_Exception $e) { if (!isset($apiRequest)) { $apiRequest = array(); } if (CRM_Utils_Array::value('format.is_success', CRM_Utils_Array::value('params', $apiRequest)) == 1) { return 0; } $data = $e->getExtraParams(); $data['entity'] = CRM_Utils_Array::value('entity', $apiRequest); $data['action'] = CRM_Utils_Array::value('action', $apiRequest); $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode()); if (CRM_Utils_Array::value('debug', CRM_Utils_Array::value('params', $apiRequest)) && empty($data['trace'])) { $err['trace'] = $e->getTraceAsString(); } if (!empty($apiRequest['is_transactional'])) { $transaction->rollback(); } return $err; } catch (Exception $e) { if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { return 0; } $data = array(); $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode()); if (!empty($apiRequest['params']['debug'])) { $err['trace'] = $e->getTraceAsString(); } if (!empty($apiRequest['is_transactional'])) { $transaction->rollback(); } return $err; } }
$conn->setPassword($pass); } break; case "sendmail": require_once TestConfiguration::SWIFT_LIBRARY_PATH . "/Swift/Connection/Sendmail.php"; $conn = new Swift_Connection_Sendmail(TestConfiguration::SENDMAIL_PATH); break; case "nativemail": require_once TestConfiguration::SWIFT_LIBRARY_PATH . "/Swift/Connection/NativeMail.php"; $conn = new Swift_Connection_NativeMail(); break; } ?> Run Test for number of recipients: <ul> <li><a href="?n=1">1</a></li> <li><a href="?n=10">10</a></li> <li><a href="?n=30">30</a></li> <li><a href="?n=100">100</a></li> </ul><?php $swift = new Swift($conn); $message = new Swift_Message("Test", "Test"); $from = new Swift_Address(TestConfiguration::FROM_ADDRESS, TestConfiguration::FROM_NAME); $to = new Swift_Address(TestConfiguration::TO_ADDRESS, TestConfiguration::TO_NAME); for ($i = 0; $i < $n; $i++) { $swift->send($message, $to, $from); } xdebug_stop_trace(); echo "Check the output file [" . TestConfiguration::WRITABLE_PATH . "/bench-output.xt] for the trace if the peak memory value below is zero<br />"; echo xdebug_peak_memory_usage();
/** * Rendering function on Shutdown of XDEBUG. */ public static function render() { // Start XDEBUG Tracing and Coverage if (self::isXdebugActive()) { /* * This is the CSS for XDebug Fatal Error */ echo '<!-- Disable XDebug Mode to remove this!--> <style type="text/css"> /*<![CDATA[*/ table.xdebug-error { font-size: 12px; width: 95%; margin: 0 auto 10px auto; border-color: #666; border-collapse: collapse; border-style: outset; color: #222222; } .xdebug-error th { background: none repeat scroll 0 0 #E03937; border: 1px inset #BF0000; font-weight: bold; padding: 3px; font-size: 16px; } .xdebug-error td { background: none repeat scroll 0 0 #FFFFCC; border: 1px solid grey; padding: 2px 2px 2px 5px; vertical-align: top; } .xdebug-error tr:hover td { background: #ffff88; } .xdebug-error span { display: none; } /** Custom Styles not related to XDEBUG **/ .toggle { font-size: 12px; color: white; float: left; } /*]]>*/ </style>'; /* * Reset for hardcoded bgcolor attributes in the "xdebug-error" table. * This will select all <td> elements and reset the bgcolor attribute on each element. */ echo "<script type=\"text/javascript\">\n var xdebugErrorTable = document.getElementsByClassName('xdebug-error');\n if (xdebugErrorTable.length > 0) {\n var xdebugErrorTableTds =\n document.getElementsByClassName('xdebug-error')[0].getElementsByTagName('td');\n for (var i = 0; i < xdebugErrorTableTds.length; i++) {\n xdebugErrorTableTds[i].setAttribute('bgcolor', '');\n }\n }"; /* * Visibility Toggle + Toggle Text Change */ echo 'function toggleXDebugTable(a) {document.getElementById(a).style.display=="none" ?(document.getElementById(a).style.display="table", document.getElementById("toggle-icon-"+a).innerHTML="▼") :(document.getElementById(a).style.display="none", document.getElementById("toggle-icon-"+a).innerHTML="►")};'; echo '</script>'; /* * This is the CSS for XDebug Console via xdebug_dump_superglobals() */ echo '<!-- Disable XDebug Mode to remove this!--> <style type="text/css"> /*<![CDATA[*/ /* center outer div */ #x-debug { width: 95%; padding:20px 0px 10px 0px; background: #EFEFEF; border: 1px solid #333; margin: 0 auto; /* centering */ margin-top: 15px; margin-bottom: 15px; } table.xdebug-console, table.xdebug-superglobals { width: 100%; background: none repeat scroll 0 0 #FFFFCC; border-width: 1px; border-style: outset; border-color: #BF0000; border-collapse: collapse; color: #222; font: 12px tahoma,verdana,arial,sans-serif; margin-top: 5px; margin-bottom: 8px; } table.xdebug-console th, table.xdebug-superglobals th { border: 1px inset #BF0000; padding: 3px; padding-bottom: 3px; font-weight: bold; background: #E03937; text-align: left; } .xdebug-superglobals td { border: 1px solid grey; padding: 2px; padding-left: 5px; vertical-align:top; } table.xdebug-console td { border: 1px inset grey; padding: 2px; padding-left: 5px; } table.xdebug-console td.td1 {width: 30%; padding-left:20px; color:#FF0000; } table.xdebug-console td.td2 {width: 70%;} table.xdebug-console tr:hover td, table.xdebug-superglobals tr:hover td { background: #ffff88; } fieldset.xdebug-console { background: none repeat scroll 0 0 #ccc; border: 1px solid #666666; font: 12px tahoma,verdana,arial,sans-serif; margin: 35px; padding: 10px; width: 95%; } fieldset.xdebug-console legend { background: #fff; border: 1px solid #333; font-weight: bold; padding: 5px 15px; color: #222; float: left; margin-top: -23px; margin-bottom: 10px; } fieldset.xdebug-console pre { margin: 2px; text-align: left; width: 100%; } /*]]>*/ </style> <!--[if IE]> <style type="text/css"> fieldset.xdebug-console legend { position:relative; top: -0.2em; } </style> <![endif]-->'; echo '<fieldset class="xdebug-console"><legend>XDebug Console</legend>'; echo xdebug_dump_superglobals(); echo '<table class="xdebug-console">'; echo '<tr><th>Name</th><th>Value</th></tr>'; echo '<tr>'; echo '<td class="td1">Time to execute</td>'; echo '<td class="td2">' . round(xdebug_time_index(), 4) . ' seconds</td>'; echo '</tr><tr>'; echo '<td class="td1">Memory Usage (before)</td>'; echo '<td class="td2">' . self::$xdebug_memory_before . ' MB</td>'; echo '</tr><tr>'; echo '<td class="td1">Memory Usage by ' . APPLICATION_NAME . ' </td>'; echo '<td class="td2">' . self::roundMB(xdebug_memory_usage()) . ' MB</td>'; echo '</tr><tr>'; echo '<td class="td1">Memory Peak</td>'; echo '<td class="td2">' . self::roundMB(xdebug_peak_memory_usage()) . ' MB</td>'; echo '</tr>'; // stop tracings and var_dump #var_dump(xdebug_get_code_coverage()); echo '</table>'; self::showConstants(); #self::showBrowserInfo(); self::showHttpHeaders(); echo '</table>'; echo '</fieldset>'; /* * Reset for hardcoded bgcolor attributes in the "xdebug-superglobals" table. * This will select all <td> elements and reset the bgcolor attribute on each element. */ echo "<script type=\"text/javascript\">\n var xdebugTds = document.getElementsByClassName('xdebug-superglobals')[0].getElementsByTagName('td');\n for (var i = 0; i < xdebugTds.length; i++) {xdebugTds[i].setAttribute('bgcolor', '');}\n xdebugTds[0].setAttribute('width', '30%');\n </script>"; } }
/** * Send HTTP response body and create performance.log * */ public function reply($data) { $this->response->sendHeader(); echo $data; if (function_exists("xdebug_time_index")) { $filename = 'app/log/performance.log'; $time = $this->getRequestURI() . " took " . round(xdebug_time_index(), 5) . " seconds\n"; $time .= "Used " . round(xdebug_memory_usage() / 1024, 5) . "Kb of Memory\n"; $time .= "Used at peak " . round(xdebug_peak_memory_usage() / 1024, 5) . "Kb of Memory\n"; if (is_writeable($filename)) { file_put_contents($filename, $time); } } }
/** * Print common footer : * conf->global->MAIN_HTML_FOOTER * conf->global->MAIN_GOOGLE_AN_ID * DOL_TUNING * conf->logbuffer * * @param string $zone 'private' (for private pages) or 'public' (for public pages) * @return void */ function printCommonFooter($zone = 'private') { global $conf; global $micro_start_time; if ($zone == 'private') { print "\n" . '<!-- Common footer for private page -->' . "\n"; } else { print "\n" . '<!-- Common footer for public page -->' . "\n"; } if (!empty($conf->global->MAIN_HTML_FOOTER)) { print $conf->global->MAIN_HTML_FOOTER . "\n"; } // Google Analytics (need Google module) if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) { if (empty($conf->dol_use_jmobile)) { print "\n"; print '<script type="text/javascript">' . "\n"; print ' var _gaq = _gaq || [];' . "\n"; print ' _gaq.push([\'_setAccount\', \'' . $conf->global->MAIN_GOOGLE_AN_ID . '\']);' . "\n"; print ' _gaq.push([\'_trackPageview\']);' . "\n"; print '' . "\n"; print ' (function() {' . "\n"; print ' var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;' . "\n"; print ' ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';' . "\n"; print ' var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);' . "\n"; print ' })();' . "\n"; print '</script>' . "\n"; } } // End of tuning if (!empty($_SERVER['DOL_TUNING']) || !empty($conf->global->MAIN_SHOW_TUNING_INFO)) { print "\n" . '<script type="text/javascript">' . "\n"; print 'window.console && console.log("'; if (!empty($conf->global->MEMCACHED_SERVER)) { print 'MEMCACHED_SERVER=' . $conf->global->MEMCACHED_SERVER . ' - '; } print 'MAIN_OPTIMIZE_SPEED=' . (isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off'); if ($micro_start_time) { $micro_end_time = dol_microtime_float(true); print ' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) . ' ms'; } if (function_exists("memory_get_usage")) { print ' - Mem: ' . memory_get_usage(); } if (function_exists("xdebug_memory_usage")) { print ' - XDebug time: ' . ceil(1000 * xdebug_time_index()) . ' ms'; print ' - XDebug mem: ' . xdebug_memory_usage(); print ' - XDebug mem peak: ' . xdebug_peak_memory_usage(); } if (function_exists("zend_loader_file_encoded")) { print ' - Zend encoded file: ' . (zend_loader_file_encoded() ? 'yes' : 'no'); } print '");' . "\n"; print '</script>' . "\n"; // Add Xdebug coverage of code if (defined('XDEBUGCOVERAGE')) { var_dump(xdebug_get_code_coverage()); } } // If there is some logs in buffer to show if (count($conf->logbuffer)) { print "\n"; print "<!-- Start of log output\n"; //print '<div class="hidden">'."\n"; foreach ($conf->logbuffer as $logline) { print $logline . "<br>\n"; } //print '</div>'."\n"; print "End of log output -->\n"; } }
public static function displayPublicAdminBar($okt) { $aBasesUrl = new ArrayObject(); $aPrimaryAdminBar = new ArrayObject(); $aSecondaryAdminBar = new ArrayObject(); $aBasesUrl['admin'] = $okt->config->app_path . OKT_ADMIN_DIR; $aBasesUrl['logout'] = $aBasesUrl['admin'] . '/index.php?logout=1'; $aBasesUrl['profil'] = $aBasesUrl['admin']; # -- CORE TRIGGER : publicAdminBarBeforeDefaultsItems $okt->triggers->callTrigger('publicAdminBarBeforeDefaultsItems', $okt, $aPrimaryAdminBar, $aSecondaryAdminBar, $aBasesUrl); # éléments première barre $aPrimaryAdminBar[10] = array('intitle' => '<img src="' . OKT_PUBLIC_URL . '/img/notify/error.png" width="22" height="22" alt="' . __('c_c_warning') . '" />', 'items' => array()); $aPrimaryAdminBar[100] = array('href' => $aBasesUrl['admin'], 'intitle' => __('c_c_administration')); $aPrimaryAdminBar[200] = array('intitle' => __('c_c_action_Add'), 'items' => array()); # éléments seconde barre $aSecondaryAdminBar[100] = array('href' => $aBasesUrl['profil'], 'intitle' => sprintf(__('c_c_user_hello_%s'), html::escapeHTML(oktAuth::getUserCN($okt->user->username, $okt->user->lastname, $okt->user->firstname)))); if (!$okt->languages->unique) { $iStartIdx = 150; foreach ($okt->languages->list as $aLanguage) { if ($aLanguage['code'] == $okt->user->language) { continue; } $aSecondaryAdminBar[$iStartIdx++] = array('href' => html::escapeHTML($okt->config->app_path . $aLanguage['code'] . '/'), 'title' => html::escapeHTML($aLanguage['title']), 'intitle' => '<img src="' . OKT_PUBLIC_URL . '/img/flags/' . $aLanguage['img'] . '" alt="' . html::escapeHTML($aLanguage['title']) . '" />'); } } $aSecondaryAdminBar[200] = array('href' => $aBasesUrl['logout'], 'intitle' => __('c_c_user_log_off_action')); # infos super-admin if ($okt->checkPerm('is_superadmin')) { # avertissement nouvelle version disponible if ($okt->config->update_enabled && is_readable(OKT_DIGESTS)) { $updater = new oktUpdate($okt->config->update_url, 'okatea', $okt->config->update_type, OKT_CACHE_PATH . '/versions'); $new_v = $updater->check(util::getVersion()); if ($updater->getNotify() && $new_v) { # locales l10n::set(OKT_LOCALES_PATH . '/' . $okt->user->language . '/admin.update'); $aPrimaryAdminBar[10]['items'][100] = array('href' => $aBasesUrl['admin'] . '/configuration.php?action=update', 'intitle' => sprintf(__('c_a_update_okatea_%s_available'), $new_v)); } } # avertissement mode maintenance est activé sur la partie publique if ($okt->config->public_maintenance_mode) { $aPrimaryAdminBar[10]['items'][300] = array('href' => $aBasesUrl['admin'] . '/configuration.php?action=advanced#tab_others', 'intitle' => sprintf(__('c_a_public_maintenance_mode_enabled'), $new_v)); } # avertissement mode maintenance est activé sur l'admin if ($okt->config->admin_maintenance_mode) { $aPrimaryAdminBar[10]['items'][400] = array('href' => $aBasesUrl['admin'] . '/configuration.php?action=advanced#tab_others', 'intitle' => sprintf(__('c_a_admin_maintenance_mode_enabled'), $new_v)); } # info execution $aExecInfos = array(); $aExecInfos['execTime'] = util::getExecutionTime(); if (OKT_XDEBUG) { $aExecInfos['memUsage'] = util::l10nFileSize(xdebug_memory_usage()); $aExecInfos['peakUsage'] = util::l10nFileSize(xdebug_peak_memory_usage()); } else { $aExecInfos['memUsage'] = util::l10nFileSize(memory_get_usage()); $aExecInfos['peakUsage'] = util::l10nFileSize(memory_get_peak_usage()); } $aSecondaryAdminBar[1000] = array('title' => $aExecInfos['execTime'] . ' s - ' . $aExecInfos['memUsage'], 'intitle' => '<img src="' . OKT_PUBLIC_URL . '/img/ico/terminal.gif" width="16" height="16" alt="" />', 'items' => array(array('intitle' => 'Temps d\'execution du script : ' . $aExecInfos['execTime'] . ' s'), array('intitle' => 'Mémoire utilisée par PHP : ' . $aExecInfos['memUsage']), array('intitle' => 'Pic mémoire allouée par PHP : ' . $aExecInfos['peakUsage']), array('intitle' => 'Router lang : ' . $okt->router->getLanguage()), array('intitle' => 'Router path : ' . $okt->router->getPath()), array('intitle' => 'Router route ID : ' . $okt->router->getFindedRouteId()))); if (!empty($okt->page->module)) { $aSecondaryAdminBar[1000]['items'][] = array('intitle' => '$okt->page->module : ' . $okt->page->module); } if (!empty($okt->page->action)) { $aSecondaryAdminBar[1000]['items'][] = array('intitle' => '$okt->page->action : ' . $okt->page->action); } } # -- CORE TRIGGER : publicAdminBarItems $okt->triggers->callTrigger('publicAdminBarItems', $okt, $aPrimaryAdminBar, $aSecondaryAdminBar, $aBasesUrl); # sort items of by keys $aPrimaryAdminBar->ksort(); $aSecondaryAdminBar->ksort(); # remove empty values of admins bars $aPrimaryAdminBar = array_filter((array) $aPrimaryAdminBar); $aSecondaryAdminBar = array_filter((array) $aSecondaryAdminBar); # reverse sedond bar items $aSecondaryAdminBar = array_reverse($aSecondaryAdminBar); $class = ''; ?> <div id="oktadminbar" class="<?php echo $class; ?> " role="navigation"> <a class="screen-reader-shortcut" href="#okt-toolbar" tabindex="1"><?php _e('Skip to toolbar'); ?> </a> <div class="quicklinks" id="okt-toolbar" role="navigation" aria-label="<?php echo util::escapeAttrHTML(__('Top navigation toolbar.')); ?> " tabindex="0"> <ul class="ab-top-menu"> <?php foreach ($aPrimaryAdminBar as $aPrimaryItem) { echo self::getItems($aPrimaryItem); } ?> </ul> <ul class="ab-top-secondary ab-top-menu"> <?php foreach ($aSecondaryAdminBar as $aSecondaryItem) { echo self::getItems($aSecondaryItem); } ?> </ul> </div> <a class="screen-reader-shortcut" href="<?php echo $aBasesUrl['logout']; ?> "><?php _e('c_c_user_log_off_action'); ?> </a> </div> <?php }
<pre> <?php require 'ezc_mail_setup.php'; error_reporting(E_ALL); $parser = new ezcMailParser(); $set = new ezcMailFileSet(array(dirname(__FILE__) . '/ezcmailtest.mail')); echo "Memory: ", xdebug_memory_usage(), " bytes\n\n"; $mail = $parser->parseMail($set); foreach ($mail as $mailPart) { echo "From: {$mailPart->from->email}\n"; echo "Subject: {$mailPart->subject}\n"; } unset($mail); echo "\nMaximum Memory: ", xdebug_peak_memory_usage(), " bytes\n";
/** * Prepare template for render from View * * @throws \Exception if template path is incorrect */ public function output() { $template = $this->template; $data = $this->data; $css = $this->css; $js = $this->js; $title = $this->title; ob_start(); try { if (!file_exists(APP . "Templates/_pages/{$template}.html")) { throw new \Exception("The required Template ({$template}) not exist."); } require APP . 'Templates/_shared/header.html'; require APP . "Templates/_pages/{$template}.html"; require APP . 'Templates/_shared/footer.html'; } catch (\Exception $e) { echo 'Template exception: ', $e->getMessage(), "\n"; } //only for debug, return time execution and memory usage echo '<!-- Memory: '; echo round(xdebug_memory_usage() / 1024, 2), ' ('; echo round(xdebug_peak_memory_usage() / 1024, 2), ') KByte - Time: '; echo xdebug_time_index(); echo ' Seconds -->'; ob_end_flush(); }
function llxFooter($foot = '') { global $conf, $langs, $dolibarr_auto_user, $micro_start_time; // Core error message if (defined("MAIN_CORE_ERROR") && constant("MAIN_CORE_ERROR") == 1) { // Ajax version if ($conf->use_javascript_ajax) { $title = img_warning() . ' ' . $langs->trans('CoreErrorTitle'); print ajax_dialog($title, $langs->trans('CoreErrorMessage')); } else { $msg = img_warning() . ' ' . $langs->trans('CoreErrorMessage'); print '<div class="error">' . $msg . '</div>'; } define("MAIN_CORE_ERROR", 0); } print "\n\n"; if (preg_match('/^smartphone/', $conf->smart_menu) && isset($conf->browser->phone)) { print '</div> <!-- end div data-role="content" -->' . "\n"; print '</div> <!-- end div data-role="page" -->' . "\n"; } print '</div> <!-- end div class="fiche" -->' . "\n"; print "\n" . '</td></tr></table> <!-- end right area -->' . "\n"; if ($conf->use_javascript_ajax && !empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) { print '</div></div> <!-- end main layout -->' . "\n"; } print "\n"; if ($foot) { print '<!-- ' . $foot . ' -->' . "\n"; } if (!empty($conf->global->MAIN_HTML_FOOTER)) { print $conf->global->MAIN_HTML_FOOTER . "\n"; } // If there is some logs in buffer to show if (sizeof($conf->logbuffer)) { print "\n"; print "<!-- Start of log output\n"; //print '<div class="hidden">'."\n"; foreach ($conf->logbuffer as $logline) { print $logline . "<br>\n"; } //print '</div>'."\n"; print "End of log output -->\n"; } // End of tuning if (!empty($_SERVER['DOL_TUNING'])) { $micro_end_time = dol_microtime_float(true); print "\n" . '<script type="text/javascript">console.log("'; if (!empty($conf->global->MEMCACHED_SERVER)) { print 'MEMCACHED_SERVER=' . $conf->global->MEMCACHED_SERVER . ' - '; } print 'MAIN_OPTIMIZE_SPEED=' . (isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off'); print ' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) . ' ms'; if (function_exists("memory_get_usage")) { print ' - Mem: ' . memory_get_usage(); } if (function_exists("xdebug_memory_usage")) { print ' - XDebug time: ' . ceil(1000 * xdebug_time_index()) . ' ms'; print ' - XDebug mem: ' . xdebug_memory_usage(); print ' - XDebug mem peak: ' . xdebug_peak_memory_usage(); } if (function_exists("zend_loader_file_encoded")) { print ' - Zend encoded file: ' . (zend_loader_file_encoded() ? 'yes' : 'no'); } print '")</script>' . "\n"; // Add Xdebug coverage of code if (defined('XDEBUGCOVERAGE')) { var_dump(xdebug_get_code_coverage()); } } print "</body>\n"; print "</html>\n"; }
include $lotusHome . 'runtime/Lotus.php'; $lotus = new Lotus(); $lotus->devMode = false; // 关闭开发模式 $lotus->option['proj_dir'] = dirname(__FILE__) . '/proj_dir/'; $lotus->option['app_name'] = 'app_name1'; $lotus->init(); /** * 使用xdebug测试性能 */ if (function_exists('xdebug_time_index') && function_exists('xdebug_peak_memory_usage')) { echo "\n<script type=\"text/javascript\">\n"; echo 'document.getElementById("debug_info").innerHTML = "'; echo xdebug_time_index(); echo ' - '; echo format_size(xdebug_peak_memory_usage()); echo "\";\n</script>\n"; } function format_size($size) { if ($size >= 1073741824) { $size = round($size / 1073741824, 2) . ' GB'; } else { if ($size >= 1048576) { $size = round($size / 1048576, 2) . ' MB'; } else { if ($size >= 1024) { $size = round($size / 1024, 2) . ' KB'; } else { $size = round($size, 2) . ' Bytes'; }
/** * Print common footer : * conf->global->MAIN_HTML_FOOTER * conf->global->MAIN_GOOGLE_AN_ID * conf->global->MAIN_SHOW_TUNING_INFO or $_SERVER["MAIN_SHOW_TUNING_INFO"] * conf->logbuffer * * @param string $zone 'private' (for private pages) or 'public' (for public pages) * @return void */ function printCommonFooter($zone = 'private') { global $conf, $hookmanager; global $micro_start_time; if ($zone == 'private') { print "\n" . '<!-- Common footer for private page -->' . "\n"; } else { print "\n" . '<!-- Common footer for public page -->' . "\n"; } if (!empty($conf->global->MAIN_HTML_FOOTER)) { print $conf->global->MAIN_HTML_FOOTER . "\n"; } print "\n"; if (!empty($conf->use_javascript_ajax)) { print '<script type="text/javascript" language="javascript">jQuery(document).ready(function() {' . "\n"; print '<!-- If page_y set, we set scollbar with it -->' . "\n"; print "page_y=getParameterByName('page_y', 0);"; print "if (page_y > 0) \$('html, body').scrollTop(page_y);"; print '<!-- Set handler to add page_y param on some a href links -->' . "\n"; print 'jQuery(".reposition").click(function() { var page_y = $(document).scrollTop(); /* alert(page_y); */ this.href=this.href+\'&page_y=\'+page_y; });' . "\n"; print '});' . "\n"; print '</script>' . "\n"; } // Google Analytics (need Google module) if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) { if (empty($conf->dol_use_jmobile)) { print "\n"; print '<script type="text/javascript">' . "\n"; print ' var _gaq = _gaq || [];' . "\n"; print ' _gaq.push([\'_setAccount\', \'' . $conf->global->MAIN_GOOGLE_AN_ID . '\']);' . "\n"; print ' _gaq.push([\'_trackPageview\']);' . "\n"; print '' . "\n"; print ' (function() {' . "\n"; print ' var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;' . "\n"; print ' ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';' . "\n"; print ' var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);' . "\n"; print ' })();' . "\n"; print '</script>' . "\n"; } } // End of tuning if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO']) || !empty($conf->global->MAIN_SHOW_TUNING_INFO)) { print "\n" . '<script type="text/javascript">' . "\n"; print 'window.console && console.log("'; if (!empty($conf->global->MEMCACHED_SERVER)) { print 'MEMCACHED_SERVER=' . $conf->global->MEMCACHED_SERVER . ' - '; } print 'MAIN_OPTIMIZE_SPEED=' . (isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off'); if ($micro_start_time) { $micro_end_time = microtime(true); print ' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) . ' ms'; } if (function_exists("memory_get_usage")) { print ' - Mem: ' . memory_get_usage(); } if (function_exists("xdebug_memory_usage")) { print ' - XDebug time: ' . ceil(1000 * xdebug_time_index()) . ' ms'; print ' - XDebug mem: ' . xdebug_memory_usage(); print ' - XDebug mem peak: ' . xdebug_peak_memory_usage(); } if (function_exists("zend_loader_file_encoded")) { print ' - Zend encoded file: ' . (zend_loader_file_encoded() ? 'yes' : 'no'); } print '");' . "\n"; print '</script>' . "\n"; // Add Xdebug coverage of code if (defined('XDEBUGCOVERAGE')) { print_r(xdebug_get_code_coverage()); } } // If there is some logs in buffer to show if (count($conf->logbuffer)) { print "\n"; print "<!-- Start of log output\n"; //print '<div class="hidden">'."\n"; foreach ($conf->logbuffer as $logline) { print $logline . "<br>\n"; } //print '</div>'."\n"; print "End of log output -->\n"; } $parameters = array(); $reshook = $hookmanager->executeHooks('printCommonFooter', $parameters); // Note that $action and $object may have been modified by some hooks }
if (file_exists($settings_file)) { include $settings_file; } $BaseTemplate->template_path = SKINS_PATH; Template::Set('MODULE_NAV_INC', $NAVBAR); Template::Set('MODULE_HEAD_INC', $HTMLHead); ob_start(); MainController::RunAllActions(); $page_content = ob_get_clean(); $BaseTemplate->Set('title', MainController::$page_title . ' - ' . SITE_NAME); $BaseTemplate->Set('page_title', MainController::$page_title . ' - ' . SITE_NAME); if (file_exists(SKINS_PATH . '/layout.tpl')) { $BaseTemplate->Set('page_htmlhead', Template::Get('core_htmlhead.tpl', true)); $BaseTemplate->Set('page_htmlreq', Template::Get('core_htmlreq.tpl', true)); $BaseTemplate->Set('page_content', $page_content); $BaseTemplate->ShowTemplate('layout.tpl'); } else { # It's a template sammich! $BaseTemplate->ShowTemplate('header.tpl'); echo $page_content; $BaseTemplate->ShowTemplate('footer.tpl'); } # Force connection close DB::close(); if (Config::Get('XDEBUG_BENCHMARK')) { $run_time = xdebug_time_index(); $memory_end = xdebug_memory_usage(); echo 'TOTAL MEMORY: ' . ($memory_end - $memory_start) . '<br />'; echo 'PEAK: ' . xdebug_peak_memory_usage() . '<br />'; echo 'RUN TIME: ' . $run_time . '<br />'; }
/** * Returns the maximum amount of memory the script used until now. * Before PHP 5.2.1, this only works if PHP is compiled with --enable-memory-limit. * From PHP 5.2.1 and later this function is always available. * * @return int */ public function peakMemoryUsage() { return xdebug_peak_memory_usage(); }
/** * Get memory usage * * @param bool $peak * @return string */ private function _debugMemoryUsage($peak = false) { $memAvail = ini_get('memory_limit'); if ($this->_xdebug) { $memUsed = $peak ? xdebug_peak_memory_usage() : xdebug_memory_usage(); } else { $memUsed = $peak ? memory_get_peak_usage() : memory_get_usage(); } $memPercent = round($memUsed / $this->_debugGetBytes($memAvail) * 100, 2); $memUsedHR = implode('', formatBytes($memUsed)); return $memUsedHR . ' / ' . $memAvail . ' (' . $memPercent . '%)'; }
public static function easybug() { self::$var['bug']['runsql'] = 0; if (!self::$var['ajax'] && function_exists('xdebug_time_index')) { self::$var['bug']['runsec'] = function_exists('xdebug_time_index') ? number_format(xdebug_time_index(), 6) : number_format(dmicrotime() - RUNFIRSTTIME, 6); $html = '<p>' . self::$var['bug']['runsec'] . 's, runsize: ' . xdebug_memory_usage() . 'Kb, runavgsize: ' . xdebug_peak_memory_usage() . 'Kb, runsql:' . var_export(self::$var['bug']['runsql'], true) . '</p>'; echo $html; } else { self::$var['bug']['runsec'] = number_format(dmicrotime() - self::$var['starttime'], 6); self::$var['bug']['runmemory'] = intval(return_bytes(memory_get_usage() / (1024 * 1024) . 'k')); self::$var['bug']['runsql'] = Factory_Db::countSqlNum(); } }
$baseImg->addEffect('PhotoStack', array('images' => $imgs, 'resize_height' => 150, 'padding' => 0, 'background' => 'blue', 'type' => 'rounded')); $baseImg->applyEffects(); $baseImg->display(); $time = xdebug_time_index() - $time; $memory = xdebug_peak_memory_usage(); logThis($test, $time, $memory); break; case 'testPolaroidstackTransparentBG': $time = xdebug_time_index(); $imgs = array(getImageObject(array('filename' => 'img1.jpg')), getImageObject(array('filename' => 'img2.jpg')), getImageObject(array('filename' => 'img3.jpg'))); $baseImg = getImageObject(array('width' => 1, 'height' => 1, 'background' => 'none')); $baseImg->addEffect('PhotoStack', array('images' => $imgs, 'resize_height' => 150, 'padding' => 0, 'background' => 'none', 'type' => 'polaroid')); $baseImg->applyEffects(); $baseImg->display(); $time = xdebug_time_index() - $time; $memory = xdebug_peak_memory_usage(); logThis($test, $time, $memory); break; case 'testPolaroidstackBlueBG': $imgs = array(getImageObject(array('filename' => 'img1.jpg')), getImageObject(array('filename' => 'img2.jpg')), getImageObject(array('filename' => 'img3.jpg'))); $baseImg = getImageObject(array('width' => 1, 'height' => 1, 'background' => 'none')); $baseImg->addEffect('PhotoStack', array('images' => $imgs, 'resize_height' => 150, 'padding' => 0, 'background' => 'blue', 'type' => 'polaroid')); $baseImg->applyEffects(); $baseImg->display(); break; } } catch (Exception $e) { $logger->err($e); header('Content-Type: image/png'); readfile('error.png'); exit;
/** * Détermine les données de la debug bar. * * @return void */ public function setData() { $this->aDebugBarData = array(); $this->aDebugBarData['num_data'] = array(); if ($this->aConfig['tabs']['super_globales']) { $this->aDebugBarData['num_data']['get'] = count($_GET); $this->aDebugBarData['num_data']['post'] = count($_POST); $this->aDebugBarData['num_data']['cookie'] = count($_COOKIE); $this->aDebugBarData['num_data']['files'] = count($_FILES); $this->aDebugBarData['num_data']['session'] = count($_SESSION); $this->aDebugBarData['num_data']['server'] = count($_SERVER); $this->aDebugBarData['num_data']['env'] = count($_ENV); $this->aDebugBarData['num_data']['request'] = count($_REQUEST); } if ($this->aConfig['tabs']['app']) { $this->aDebugBarData['definedVars'] = self::getDefinedVars(); $this->aDebugBarData['definedConstants'] = self::getDefinedConstants(); $this->aDebugBarData['configVars'] = $this->okt->config->get(); $this->aDebugBarData['userVars'] = $this->okt->user->getData(0); $this->aDebugBarData['l10nVars'] = !empty($__l10n) ? $__l10n : array(); $this->aDebugBarData['num_data']['definedVars'] = count($this->aDebugBarData['definedVars']); $this->aDebugBarData['num_data']['definedConstants'] = count($this->aDebugBarData['definedConstants']); $this->aDebugBarData['num_data']['configVars'] = count($this->aDebugBarData['configVars']); $this->aDebugBarData['num_data']['userVars'] = count($this->aDebugBarData['userVars']); $this->aDebugBarData['num_data']['l10nVars'] = count($this->aDebugBarData['l10nVars']); } if ($this->aConfig['tabs']['logs']) { $this->aDebugBarData['num_data']['logs'] = $this->okt->debug->getNum(); } if ($this->aConfig['tabs']['db']) { $this->aDebugBarData['num_data']['queries'] = $this->okt->db->nbQueries(); } if ($this->aConfig['tabs']['tools']) { $this->aDebugBarData['execTime'] = util::getExecutionTime(); if (OKT_XDEBUG) { $this->aDebugBarData['memUsage'] = util::l10nFileSize(xdebug_memory_usage()); $this->aDebugBarData['peakUsage'] = util::l10nFileSize(xdebug_peak_memory_usage()); } else { $this->aDebugBarData['memUsage'] = util::l10nFileSize(memory_get_usage()); $this->aDebugBarData['peakUsage'] = util::l10nFileSize(memory_get_peak_usage()); } } }
#print_r($habitation = $o->getRelsByClasses('Home', 'LivesIn')); print_r($habitation = $o->getRelsByClasses('Home', 'LivesIn', 'Person -> (LivesIn) -> Home')); print_r($habitation->classHome[0]); print_r($habitation->classLivesIn[0]); } #OrmSqlCache::save(); # suggested tests # 1. Orm::load # 2. OrmClass->getRelsByClasses() for direct relation # 3. OrmClass->getRelsByClasses() for indirect relation # 4. OrmClass->getRelsByClasses() for multiple relations # 5. OrmClass->getRelsByClasses() with chain # 6. OrmClass->getRelsByClasses() with chains # 7. OrmClass->getRelsByClass() without and with chain # TODO # consider adding an incrementing integer to alias so that multiple passes of the same rule are ok # this would allow the system more flexibility for a person (keep the routing part crippled though) # would need to update the SQL generation stage, and the Object creation stage # after more thought; could result in output of objects that are the same as already constructed ones # to mitigate this we could scan previously constructed objects of the same class type for equal keys (as they've just been constructed anyway) # and merely point to the same object -- use Orm->equals() to establish this # started coding this and stopped... see $seen_results # -- stopped cos i'll have to have numbers in all aliases and i'm not so sure i want that! if (sizeof($history = SSql::getQueryHistory()) > 0) { printf("Number of SQL queries: %d, SQL Query History\n%s", sizeof($history), print_r($history, true)); } if (function_exists('xdebug_peak_memory_usage')) { printf("Peak memory usage: %.3fMB\n", xdebug_peak_memory_usage() / pow(2, 20)); } #Test::summary('OrmClass'); Orm::routeFromChain(NULL, 'Person -> (LivesIn) -> Home -> (Neighbours) -> Home -> (Neighbours) -> Home', array((object) array('class' => 'LivesIn')));
function civicrm_api($entity, $action, $params, $extra = NULL) { $apiWrappers = array(CRM_Core_HTMLInputCoder::singleton()); try { require_once 'api/v3/utils.php'; require_once 'api/Exception.php'; if (!is_array($params)) { throw new API_Exception('Input variable `params` is not an array', 2000); } _civicrm_api3_initialize(); $errorScope = CRM_Core_TemporaryErrorScope::useException(); require_once 'CRM/Utils/String.php'; require_once 'CRM/Utils/Array.php'; $apiRequest = array(); $apiRequest['entity'] = CRM_Utils_String::munge($entity); $apiRequest['action'] = CRM_Utils_String::munge($action); $apiRequest['version'] = civicrm_get_api_version($params); $apiRequest['params'] = $params; $apiRequest['extra'] = $extra; // look up function, file, is_generic $apiRequest += _civicrm_api_resolve($apiRequest); if (strtolower($action) == 'create' || strtolower($action) == 'delete') { $apiRequest['is_transactional'] = 1; $tx = new CRM_Core_Transaction(); } $errorFnName = $apiRequest['version'] == 2 ? 'civicrm_create_error' : 'civicrm_api3_create_error'; if ($apiRequest['version'] > 2) { _civicrm_api3_api_check_permission($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']); } // we do this before we _civicrm_api3_swap_out_aliases($apiRequest); if (strtolower($action) != 'getfields') { if (!CRM_Utils_Array::value('id', $params)) { $apiRequest['params'] = array_merge(_civicrm_api3_getdefaults($apiRequest), $apiRequest['params']); } //if 'id' is set then only 'version' will be checked but should still be checked for consistency civicrm_api3_verify_mandatory($apiRequest['params'], NULL, _civicrm_api3_getrequired($apiRequest)); } foreach ($apiWrappers as $apiWrapper) { $apiRequest = $apiWrapper->fromApiInput($apiRequest); } $function = $apiRequest['function']; if ($apiRequest['function'] && $apiRequest['is_generic']) { // Unlike normal API implementations, generic implementations require explicit // knowledge of the entity and action (as well as $params). Bundle up these bits // into a convenient data structure. $result = $function($apiRequest); } elseif ($apiRequest['function'] && !$apiRequest['is_generic']) { _civicrm_api3_validate_fields($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']); $result = isset($extra) ? $function($apiRequest['params'], $extra) : $function($apiRequest['params']); } else { return $errorFnName("API (" . $apiRequest['entity'] . "," . $apiRequest['action'] . ") does not exist (join the API team and implement it!)"); } foreach ($apiWrappers as $apiWrapper) { $result = $apiWrapper->toApiOutput($apiRequest, $result); } if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { if ($result['is_error'] === 0) { return 1; } else { return 0; } } if (CRM_Utils_Array::value('format.only_id', $apiRequest['params']) && isset($result['id'])) { return $result['id']; } if (CRM_Utils_Array::value('is_error', $result, 0) == 0) { _civicrm_api_call_nested_api($apiRequest['params'], $result, $apiRequest['action'], $apiRequest['entity'], $apiRequest['version']); } if (CRM_Utils_Array::value('format.smarty', $apiRequest['params']) || CRM_Utils_Array::value('format_smarty', $apiRequest['params'])) { // return _civicrm_api_parse_result_through_smarty($result,$apiRequest['params']); } if (function_exists('xdebug_time_index') && CRM_Utils_Array::value('debug', $apiRequest['params']) && is_array($result)) { $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage(); $result['xdebug']['memory'] = xdebug_memory_usage(); $result['xdebug']['timeIndex'] = xdebug_time_index(); } return $result; } catch (PEAR_Exception $e) { if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { return 0; } $data = array(); $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest); if (CRM_Utils_Array::value('debug', $apiRequest['params'])) { $err['trace'] = $e->getTraceSafe(); } else { $err['tip'] = "add debug=1 to your API call to have more info about the error"; } if (CRM_Utils_Array::value('is_transactional', $apiRequest)) { $tx->rollback(); } return $err; } catch (API_Exception $e) { if (!isset($apiRequest)) { $apiRequest = array(); } if (CRM_Utils_Array::value('format.is_success', CRM_Utils_Array::value('params', $apiRequest)) == 1) { return 0; } $data = $e->getExtraParams(); $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode()); if (CRM_Utils_Array::value('debug', CRM_Utils_Array::value('params', $apiRequest))) { $err['trace'] = $e->getTraceAsString(); } if (CRM_Utils_Array::value('is_transactional', CRM_Utils_Array::value('params', $apiRequest))) { $tx->rollback(); } return $err; } catch (Exception $e) { if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { return 0; } $data = array(); $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode()); if (CRM_Utils_Array::value('debug', $apiRequest['params'])) { $err['trace'] = $e->getTraceAsString(); } if (CRM_Utils_Array::value('is_transactional', $apiRequest)) { $tx->rollback(); } return $err; } }