WordPress Development Asked by Utsav Madaan on February 1, 2021
So i was debugging my PHP code while working with WordPress site by writing to debug.log with error_log($message) or trigger_error($message).
My message in these log statements keeps on printing thousand of times in debug.log file from a same single statement declared in functions.php (for example purpose here i am logging from themes’s functions.php which results in same issue of multiple printing though i was debugging from some snippet plugin)
Accordingly to check if this issue is caused by my code their in functions.php or snippet plugin being called multiple times i tried logging wih different mechanism [chrome console log & chrome browser alert], result was php debug log message was printed multiple times though chrome console log & chrome browser alert was only one time. So i believe my code is not running multiple times but debug log messages as printed by error_log or trigger_error is printed multiple times & keeps on printing thousand of times.
So i thought it could be due to my local development enviroment than i tried same thing in a fresh wordpress installation in a real environment, same thing happened. So found no solution/explaination to it yet.
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
To be clear i want to say Log prints multiple times (& keeps printing thousand of times) each time i load a page (so 1 page load -> continuously multiple repeated log from a single log statement in functions.php)
EDIT: Checked disabling WordPress Heartbeat
So as hinted i tried disabling WordPress Heartbeat by adding piece of code i found googling to disable Heartbeat in WordPress (will check it later whether needed or not) in functions.php at the top..but still getting those log messages multiple times in single page load.
HEARTBEAT CODE ADDED TO functions.php:
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
EDIT: Checked AJAX Calls
So as hinted, I monitored all network calls to my server through chrome developer options…their are no network calls post a page is fully loaded (page loaded with get/post html + assets network calls) so no Ajax Requests to the server after page is loaded.
OK, as far as I understand, you've put this code:
$debug_log = "DEBUG-debug log";
trigger_error($debug_log);
//OR
error_log($debug_log);
directly in your functions
php` file.
It means, that this code will be executed (so new log item will be added to log file) every time the functions.php
file is loaded - so during every request to your WP.
It means, that every time someone views your page, there will be new log item added.
But... That's not all... If you're logged in, then WP sends Heartbeat requests. They will also result in new log items.
There are not so many log items logged with the same time in your log, so IMHO it's unlikely that they are printed in the same request.
PS. JS won't be executed during AJAX calls, so you won't see them multiple times.
Answered by Krzysiek Dróżdż on February 1, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP