What request am I in?
When using XDebug to debug WordPress (or to debug specific WordPress plugins), I sometimes find my breakpoints are triggered multiple times in quick succession—but not necessarily because the enclosing function is being called repeatedly within the same request. Instead, it may be happening via multiple requests coming in one after the other.
This is easy enough to figure out if each request is to a different endpoint, or has different query params, or something like that. However, if the user agent requests POST /checkout
which redirects to POST /checkout
which redirects once again to POST /checkout
(yes, this sort of thing can happen), things are a little less obvious. So, to make it easier to spot what's happening, my current habit is to set a watch (via PhpStorm's debug tools) that calls a custom function called Request_Identifier\get_id()
.
The definition for this function is something I load early on during wp-config.php
. I'll leave it to the reader to imagine the implementation, but it's pretty simple and returns a value that stays the same for the duration of each individual request, then is redefined on the next request. So, via my debug watch-list, I'll immediately see that the request is for 4fd2-jumping-banana-catfish
one request, then fa88-elephant-digger-trumpet
the next.
I could probably just have used a randomized number or hash, but I find it's a lot easier on my brain to look at and identify changes via the 'whimsical' code names.