1

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 clearity 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.

  • 3
    functions.php is run every time anyone visits a page on your website. So yes, it's going to get logged a lot. – Jacob Peattie Jan 14 at 1:54
  • Sorry i was bit unclear..i mean to say everytime i load page it prints multiple times (& keeps printing thousand of times). – Utsav Madaan Jan 14 at 9:21
  • Are you logged in? – Krzysiek Dróżdż Jan 14 at 9:23
  • Yes i am admin to the site logged in as admin...and only i am using it via local developmenet environment (local by flywheel) – Utsav Madaan Jan 14 at 9:25
0

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 functionsphp` 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.

  • So now i have added piece of code i found on internet 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. – Utsav Madaan Jan 14 at 9:41
  • Are there any AJAX requests on your site? – Krzysiek Dróżdż Jan 14 at 10:13
  • So i monitored network calls through chrome developer options to my web server...their are no network calls post a page is fully loaded (page loaded with get/post html + assets network calls) – Utsav Madaan Jan 14 at 10:41
  • Sir can you try it yourself printing log though from functions.php on your available environment with a fresh wordpress installation and as mentioned in original question i actually tried this and got the same results even with fresh wordpress installation on real server. So i believe nothing wrong with the user code/settings. – Utsav Madaan Jan 14 at 10:45
  • Are you the only one, who is opening that site? – Krzysiek Dróżdż Jan 14 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.