Support » Plugin: Query Monitor » kint with query monitor causes functions to run twice

  • I’m not sure if this is a kint problem or a Query Monitor problem so I’m submitting to both:

    For a test I have created a simple plugin that just stores an incrementing variable in $_SESSION and dumps the value before and after incrementing. Here’s the simple code:

    function myStartSession() {
    	
    	if(!session_id()) {
    		session_start();
    	}
    
    	d($_SESSION['iteration']);
    	$_SESSION['iteration'] += 1;
    	d($_SESSION['iteration']);
    }
    add_action('init', 'myStartSession');

    The expected behavior is that on every page refresh the starting value of “iteration” will be the previous end value of “iteration”. e.g.

    val = 1
    val = 2
    refresh page
    val = 2
    val = 3
    refresh page
    val = 3
    val = 4

    When I have kint + debug bar active it all works as expected. But when I have kint + query monitor active then WP behaves like it runs the functions twice, with one of the runs being kinda invisible (no output). So instead of the above expected result I get something like:

    val = 1
    val = 2
    refresh page
    val = 3
    val = 4
    refresh page
    val = 5
    val = 6

    I discovered this behavior because another plugin that I use writes an activity log to the db. With kint + query monitor active I always get duplicate entries into the database. But without that combination everything is fine.

    Here’s a screencast that walks through what I’m seeing:

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Thanks for the report Norm.

    I’m mobile currently and the video won’t load for me so I haven’t watched it.

    Are you sure the behaviour is specific to this combination of plugins? If this was happening on my site, the first thing I would look at would be whether the WordPress “Heartbeat” is firing on the page load, which performs an Ajax call which would cause the init hook to trigger again, and for a server-side WP-Cron call, which will also cause the init hook to trigger again.

    You can see the former in the Network tab of your browser developer tools. You can see the latter in the HTTP API panel in Query Monitor.

    Thanks John. I haven’t found another combination of plugins besides king + query monitor that behaves this way. Of course, that doesn’t mean there isn’t another combo… 😉

    I’m not seeing the WP heartbeat fire on page load nor am I seeing any server-side Cron fire.

    I just tried it again and checked. I’m still easily able to see the issue with kint + query monitor while kint + debug bar works fine.

    BTW: in the video I also show another issue that shows up when I have kint active, and then from the plugins page I try to activate query monitor. The page reload seems to hang. I’m also seeing the same issue when I try to activate debug bar after kint is active. I erroneously stated in the video that I only saw it with kint + query monitor.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.