The TAGS code uses the StringMatcher class. It's functionality is similar to fnmatch.
Check if that is the case, and simplify the StringMatcher code to use fnmatch as well.
Further notes from Niklas,
I believe PHP's fnmatch is pretty well optimized. See for example https://research.swtch.com/glob, which does not talk about PHP, but suggests that linear time algorithm is what we want. I looked at the PHP code briefly and seemed okay.