un-bundle context.php
This commit is contained in:
parent
df3f061533
commit
c7ca2f4154
6 changed files with 69 additions and 85 deletions
|
@ -29,6 +29,7 @@
|
||||||
"ifixit/php-akismet" : "1.*",
|
"ifixit/php-akismet" : "1.*",
|
||||||
"google/recaptcha" : "~1.1",
|
"google/recaptcha" : "~1.1",
|
||||||
"dapphp/securimage" : "3.6.*",
|
"dapphp/securimage" : "3.6.*",
|
||||||
|
"shish/libcontext-php" : "dev-master",
|
||||||
|
|
||||||
"bower-asset/jquery" : "1.12.3",
|
"bower-asset/jquery" : "1.12.3",
|
||||||
"bower-asset/jquery-timeago" : "1.5.2",
|
"bower-asset/jquery-timeago" : "1.5.2",
|
||||||
|
|
44
composer.lock
generated
44
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "ca673d1ec39051720ade02039e5e2b4e",
|
"content-hash": "eb5180245fbf27fb02d9a4018a2ff059",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "bower-asset/jquery",
|
"name": "bower-asset/jquery",
|
||||||
|
@ -259,6 +259,47 @@
|
||||||
"reference": "fd4ff50eb577457c1b7b887401663e91e77625ae"
|
"reference": "fd4ff50eb577457c1b7b887401663e91e77625ae"
|
||||||
},
|
},
|
||||||
"type": "library"
|
"type": "library"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "shish/libcontext-php",
|
||||||
|
"version": "dev-master",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/shish/libcontext-php.git",
|
||||||
|
"reference": "7c80a23c56cfb207c02c18292720d3bd5aac474d"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/shish/libcontext-php/zipball/7c80a23c56cfb207c02c18292720d3bd5aac474d",
|
||||||
|
"reference": "7c80a23c56cfb207c02c18292720d3bd5aac474d",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "6.*"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Shish",
|
||||||
|
"email": "webmaster@shishnet.org",
|
||||||
|
"homepage": "http://shishnet.org",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A performance monitoring thing",
|
||||||
|
"homepage": "https://github.com/shish/libcontext-php",
|
||||||
|
"keywords": [
|
||||||
|
"performance",
|
||||||
|
"profiler"
|
||||||
|
],
|
||||||
|
"time": "2017-09-21T03:48:29+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
@ -1715,6 +1756,7 @@
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"stability-flags": {
|
"stability-flags": {
|
||||||
|
"shish/libcontext-php": 20,
|
||||||
"bower-asset/tablesorter": 20
|
"bower-asset/tablesorter": 20
|
||||||
},
|
},
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
* actually do anything as far as the app is concerned
|
* actually do anything as far as the app is concerned
|
||||||
*/
|
*/
|
||||||
|
|
||||||
global $config, $database, $user, $page;
|
global $config, $database, $user, $page, $_shm_ctx;
|
||||||
|
|
||||||
require_once "core/sys_config.inc.php";
|
require_once "core/sys_config.inc.php";
|
||||||
require_once "core/util.inc.php";
|
require_once "core/util.inc.php";
|
||||||
require_once "lib/context.php";
|
require_once "vendor/shish/libcontext-php/context.php";
|
||||||
require_once "vendor/autoload.php";
|
require_once "vendor/autoload.php";
|
||||||
require_once "core/imageboard.pack.php";
|
require_once "core/imageboard.pack.php";
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ _version_check();
|
||||||
_sanitise_environment();
|
_sanitise_environment();
|
||||||
|
|
||||||
// load base files
|
// load base files
|
||||||
ctx_log_start("Opening files");
|
$_shm_ctx->log_start("Opening files");
|
||||||
$_shm_files = array_merge(
|
$_shm_files = array_merge(
|
||||||
zglob("core/*.php"),
|
zglob("core/*.php"),
|
||||||
zglob("ext/{".ENABLED_EXTS."}/main.php")
|
zglob("ext/{".ENABLED_EXTS."}/main.php")
|
||||||
|
@ -29,22 +29,22 @@ foreach($_shm_files as $_shm_filename) {
|
||||||
}
|
}
|
||||||
unset($_shm_files);
|
unset($_shm_files);
|
||||||
unset($_shm_filename);
|
unset($_shm_filename);
|
||||||
ctx_log_endok();
|
$_shm_ctx->log_endok();
|
||||||
|
|
||||||
// connect to the database
|
// connect to the database
|
||||||
ctx_log_start("Connecting to DB");
|
$_shm_ctx->log_start("Connecting to DB");
|
||||||
$database = new Database();
|
$database = new Database();
|
||||||
$config = new DatabaseConfig($database);
|
$config = new DatabaseConfig($database);
|
||||||
ctx_log_endok();
|
$_shm_ctx->log_endok();
|
||||||
|
|
||||||
// load the theme parts
|
// load the theme parts
|
||||||
ctx_log_start("Loading themelets");
|
$_shm_ctx->log_start("Loading themelets");
|
||||||
foreach(_get_themelet_files(get_theme()) as $themelet) {
|
foreach(_get_themelet_files(get_theme()) as $themelet) {
|
||||||
require_once $themelet;
|
require_once $themelet;
|
||||||
}
|
}
|
||||||
unset($themelet);
|
unset($themelet);
|
||||||
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
|
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
|
||||||
ctx_log_endok();
|
$_shm_ctx->log_endok();
|
||||||
|
|
||||||
// hook up event handlers
|
// hook up event handlers
|
||||||
_load_event_listeners();
|
_load_event_listeners();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
require_once "lib/context.php";
|
require_once "vendor/shish/libcontext-php/context.php";
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||||
* Input / Output Sanitising *
|
* Input / Output Sanitising *
|
||||||
|
@ -1466,9 +1466,9 @@ global $_shm_event_listeners;
|
||||||
$_shm_event_listeners = array();
|
$_shm_event_listeners = array();
|
||||||
|
|
||||||
function _load_event_listeners() {
|
function _load_event_listeners() {
|
||||||
global $_shm_event_listeners;
|
global $_shm_event_listeners, $_shm_ctx;
|
||||||
|
|
||||||
ctx_log_start("Loading extensions");
|
$_shm_ctx->log_start("Loading extensions");
|
||||||
|
|
||||||
$cache_path = data_path("cache/shm_event_listeners.php");
|
$cache_path = data_path("cache/shm_event_listeners.php");
|
||||||
if(COMPILE_ELS && file_exists($cache_path)) {
|
if(COMPILE_ELS && file_exists($cache_path)) {
|
||||||
|
@ -1482,7 +1482,7 @@ function _load_event_listeners() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx_log_endok();
|
$_shm_ctx->log_endok();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _set_event_listeners() {
|
function _set_event_listeners() {
|
||||||
|
@ -1568,27 +1568,27 @@ $_shm_event_count = 0;
|
||||||
* @param Event $event
|
* @param Event $event
|
||||||
*/
|
*/
|
||||||
function send_event(Event $event) {
|
function send_event(Event $event) {
|
||||||
global $_shm_event_listeners, $_shm_event_count;
|
global $_shm_event_listeners, $_shm_event_count, $_shm_ctx;
|
||||||
if(!isset($_shm_event_listeners[get_class($event)])) return;
|
if(!isset($_shm_event_listeners[get_class($event)])) return;
|
||||||
$method_name = "on".str_replace("Event", "", get_class($event));
|
$method_name = "on".str_replace("Event", "", get_class($event));
|
||||||
|
|
||||||
// send_event() is performance sensitive, and with the number
|
// send_event() is performance sensitive, and with the number
|
||||||
// of times context gets called the time starts to add up
|
// of times context gets called the time starts to add up
|
||||||
$ctx = constant('CONTEXT');
|
$ctx_enabled = constant('CONTEXT');
|
||||||
|
|
||||||
if($ctx) ctx_log_start(get_class($event));
|
if($ctx_enabled) $_shm_ctx->log_start(get_class($event));
|
||||||
// SHIT: http://bugs.php.net/bug.php?id=35106
|
// SHIT: http://bugs.php.net/bug.php?id=35106
|
||||||
$my_event_listeners = $_shm_event_listeners[get_class($event)];
|
$my_event_listeners = $_shm_event_listeners[get_class($event)];
|
||||||
ksort($my_event_listeners);
|
ksort($my_event_listeners);
|
||||||
foreach($my_event_listeners as $listener) {
|
foreach($my_event_listeners as $listener) {
|
||||||
if($ctx) ctx_log_start(get_class($listener));
|
if($ctx_enabled) $_shm_ctx->log_start(get_class($listener));
|
||||||
if(method_exists($listener, $method_name)) {
|
if(method_exists($listener, $method_name)) {
|
||||||
$listener->$method_name($event);
|
$listener->$method_name($event);
|
||||||
}
|
}
|
||||||
if($ctx) ctx_log_endok();
|
if($ctx_enabled) $_shm_ctx->log_endok();
|
||||||
}
|
}
|
||||||
$_shm_event_count++;
|
$_shm_event_count++;
|
||||||
if($ctx) ctx_log_endok();
|
if($ctx_enabled) $_shm_ctx->log_endok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1666,6 +1666,8 @@ date and you should plan on moving elsewhere.
|
||||||
}
|
}
|
||||||
|
|
||||||
function _sanitise_environment() {
|
function _sanitise_environment() {
|
||||||
|
global $_shm_ctx;
|
||||||
|
|
||||||
if(TIMEZONE) {
|
if(TIMEZONE) {
|
||||||
date_default_timezone_set(TIMEZONE);
|
date_default_timezone_set(TIMEZONE);
|
||||||
}
|
}
|
||||||
|
@ -1679,8 +1681,9 @@ function _sanitise_environment() {
|
||||||
assert_options(ASSERT_CALLBACK, 'score_assert_handler');
|
assert_options(ASSERT_CALLBACK, 'score_assert_handler');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$_shm_ctx = new Context();
|
||||||
if(CONTEXT) {
|
if(CONTEXT) {
|
||||||
ctx_set_log(CONTEXT);
|
$_shm_ctx->set_log(CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(COVERAGE) {
|
if(COVERAGE) {
|
||||||
|
|
|
@ -87,7 +87,7 @@ EOD;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
require_once "core/_bootstrap.inc.php";
|
require_once "core/_bootstrap.inc.php";
|
||||||
ctx_log_start(@$_SERVER["REQUEST_URI"], true, true);
|
$_shm_ctx->log_start(@$_SERVER["REQUEST_URI"], true, true);
|
||||||
|
|
||||||
// start the page generation waterfall
|
// start the page generation waterfall
|
||||||
$user = _get_user();
|
$user = _get_user();
|
||||||
|
@ -102,11 +102,11 @@ try {
|
||||||
// saving cache data and profiling data to disk can happen later
|
// saving cache data and profiling data to disk can happen later
|
||||||
if(function_exists("fastcgi_finish_request")) fastcgi_finish_request();
|
if(function_exists("fastcgi_finish_request")) fastcgi_finish_request();
|
||||||
$database->commit();
|
$database->commit();
|
||||||
ctx_log_endok();
|
$_shm_ctx->log_endok();
|
||||||
}
|
}
|
||||||
catch(Exception $e) {
|
catch(Exception $e) {
|
||||||
if($database) $database->rollback();
|
if($database) $database->rollback();
|
||||||
_fatal_error($e);
|
_fatal_error($e);
|
||||||
ctx_log_ender();
|
$_shm_ctx->log_ender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
<?php
|
|
||||||
$_context_log = null;
|
|
||||||
|
|
||||||
function ctx_set_log($name) {
|
|
||||||
global $_context_log;
|
|
||||||
if($name) {
|
|
||||||
$_context_log = fopen($name, "a");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$_context_log = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function ctx_log_msg($func, $text, $type) {
|
|
||||||
global $_context_log;
|
|
||||||
if($_context_log) {
|
|
||||||
fprintf(
|
|
||||||
$_context_log,
|
|
||||||
"%f %s %d %d %s %s %s\n",
|
|
||||||
microtime(true), # returning a float is 5.0+
|
|
||||||
php_uname('n'), # gethostname() is 5.3+
|
|
||||||
posix_getpid(),
|
|
||||||
function_exists("hphp_get_thread_id") ? hphp_get_thread_id() : posix_getpid(),
|
|
||||||
$type, $func, $text
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function __get_func() {
|
|
||||||
$stack = debug_backtrace();
|
|
||||||
if(count($stack) < 3) {
|
|
||||||
return "top-level";
|
|
||||||
}
|
|
||||||
$p = $stack[2];
|
|
||||||
return $p['function'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function ctx_log_bmark($text=null) {ctx_log_msg(__get_func(), $text, "BMARK");}
|
|
||||||
function ctx_log_clear($text=null) {ctx_log_msg(__get_func(), $text, "CLEAR");}
|
|
||||||
|
|
||||||
function ctx_log_start($text=null, $bookmark=false, $clear=false) {
|
|
||||||
if($clear) {
|
|
||||||
ctx_log_msg(__get_func(), $text, "CLEAR");
|
|
||||||
}
|
|
||||||
if($bookmark) {
|
|
||||||
ctx_log_msg(__get_func(), $text, "BMARK");
|
|
||||||
}
|
|
||||||
ctx_log_msg(__get_func(), $text, "START");
|
|
||||||
}
|
|
||||||
function ctx_log_endok($text=null, $clear=false) {
|
|
||||||
ctx_log_msg(__get_func(), $text, "ENDOK");
|
|
||||||
if($clear) {
|
|
||||||
ctx_log_msg(__get_func(), $text, "ENDER");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function ctx_log_ender($text=null, $clear=false) {
|
|
||||||
ctx_log_msg(__get_func(), $text, "ENDER");
|
|
||||||
if($clear) {
|
|
||||||
ctx_log_msg(__get_func(), $text, "ENDER");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
Reference in a new issue