因此,我在使用Wordpress站点时,通过编写调试来调试PHP代码。使用error\\u log($message)或trigger\\u error($message)记录日志。
我在这些日志语句中的消息在调试中不断打印数千次。来自函数中声明的同一条语句的日志文件。php(例如purpose here,我从themes\'s functions.php中登录,虽然我在调试一些代码片段插件,但这会导致同一问题的多次打印)
相应地,检查此问题是否是由其函数中的代码引起的。php或代码片段插件被多次调用我尝试使用不同的机制记录日志[chrome控制台日志和chrome浏览器警报],结果是通过chrome控制台日志和;chrome浏览器警报只有一次。因此,我相信我的代码不会多次运行,但会多次打印由error\\u log或trigger\\u error打印的调试日志消息;持续打印数千次。
因此,我认为这可能是由于我当地的开发环境,而不是我在真实环境中的新wordpress安装中尝试了同样的事情,同样的事情发生了。因此,尚未找到解决方案/解释。
MY THEME\'S functions.php WITH ALL TESTED CODE:
.
.
.
//continuously keeps on printing in debug.log (many times)
$debug_log = "DEBUG-debug log";
trigger_error($debug_log);
//OR
error_log($debug_log);
//prints only one time in chrome console
$debug_console = "DEBUG-console";
echo "<script>console.log(\'$debug_console\');</script>";
//alerts only one time in chrome
$debug_alert = "DEBUG-alert";
echo "<script type=\'text/javascript\'>alert(\'$debug_alert\');</script>";
MY debug.log FILE IS LIKE THIS:[14-Jan-2019 01:05:50 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:51 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:51 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:54 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:55 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:59 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:04 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:25 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:26 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:26 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:27 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:29 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:31 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:31 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:31 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:32 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:47 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:02 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:17 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:29 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:31 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:32 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:47 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:08:02 UTC] PHP Notice: DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
EDIT: Question clarity要明确的是,我想说,每次加载一个页面时,日志都会打印多次(&;保持打印数千次)(因此,每次加载一个页面->;从functions.php中的单个Log语句中连续多次重复日志)
EDIT: Checked disabling WordPress Heartbeat因此,正如我暗示的那样,我试图通过添加一段代码来禁用Wordpress心跳,这段代码是我在Google上找到的,可以在函数中禁用Wordpress中的心跳(稍后将检查是否需要)。php位于顶部。。但仍然在单页加载中多次获取这些日志消息。
HEARTBEAT CODE ADDED TO functions.php:
add_action( \'init\', \'stop_heartbeat\', 1 );
function stop_heartbeat() {
wp_deregister_script(\'heartbeat\');
}
EDIT: Checked AJAX Calls正如所暗示的,我通过chrome开发者选项监控了所有对我服务器的网络调用。。。他们在页面完全加载后没有网络调用(页面加载了get/post html+资产网络调用),因此在页面加载后没有对服务器的Ajax请求。