Microsoft requested that I repair my installation of Visual Studio to see if the problem remains. Here is my reply to them:
I ran a repair on 17.5.1 as requested. The problem was unchanged. Clicking on the Background Task icon displayed “Discovering files in <project name>” and “Indexing files in <project name>” indefinitely (I let it run for 30 minutes). I did this with a project that has 143 php files, although the problem exists with all of my php projects.
I opened the same php project on a different computer with Visual Studio 17.4.3. It completed the “Discovering files” task in 12 seconds and the “Indexing files” task in 18 seconds.
This is a problem in 17.5.1 that didn’t exist in 17.4.3.
Note that both projects use the PHP Tools for Visual Studio 2022 (version 1.71.17177) DEVSENSE extension which allows for php projects in Visual Studio.
Other users have reported this problem on the DEVSENSE support forum.