Php-kit Prismic client search results are inconsistent

I’m debugging a strange issue where some of my users cannot see my documents when most other users can. My website has an integration with Prismic where we fetch documents and render them based on the URL the user visits on our site.

To fetch the Prismic documents I’m using the Api.php code from this git repository:

I’m querying my Repository using the Prismic API: and I query by document.type, path_prefix, and slug.

Most of my site visitors (about 1500 so far) are able to load the page without issue.
About 30 of my site visitors repeatedly get an error and the document does not load.

The only way I’m able to reproduce the issue is by copying the cookies of my affected users. If they try private/incognito browser sessions they are able to view my page, but if they log in to their user account for my site their cookies are set and they get a 404 page again. I haven’t been able to find anything the users have in common with each other and it’s starting to look like something in their cookies is altering the query results.

Here are my query parameters:

  • [my.features.path_prefix] => features
  • [my.features.slug] => bethechange

In the query results (for a non-affected user), I get multiple documents back with the following slugs:

  • [0] => bethechange
  • [1] => be-the-change
  • [2] => test-caro-btc
  • [3] => test-be-the-change-2020
  • [4] => be-the-change-2020

When affected users go to my webpage, they trigger a search with the same path_prefix and slug, but they get back 0 documents. Has anyone seen this type of behavior before?

Hi @robert.doidge. This is a very strange issue that I haven’t seen before. Can you provide us with more information about this?

At the very least it would be helpful to see your site and try to reproduce the issue here. Can you send the url for your site and the cookies required to see the issue?

Hi @levi. I’m checking to see if I can get a cookie to share so you could reproduce the issue. It’s tricky since the one cookie I have gives too much access to our site.

Is there any additional debugging I could enable with the PHP Prismic client? Potentially to fully debug the search parameters and response. Or to possibly rule out a situation where the client is trying (and failing) to load an experiment or preview instead of the published document?

@robert.doidge I don’t think that the Prismic PHP kit has any additional debugging options. But obviously the more info you provide will help us be able to determine the issue more quickly.

I added more debugging and was able to track down the problem, which is entirely on my end.

The query function definition looks like this:
public function query($q, $options = array()) { //…

I was logging the $q variable but not the $options.
In our code we were sometimes passing an alternate ‘lang’ value for some users based on the language associated with their first visit to our website (identified in the cookie).

The fix on our end was to use the user’s language setting rather than this “original visit” language and to add code to fall back to querying for the en-us document if the document was not translated into the requested language.

Thank you for your help Levi, it got me thinking of other things to debug which led to the discovery of our error.

Excellent, I’m so happy that you were able to sort it out :grinning: