Here's the problem: I have a website, cached by varnish, on which I want to do some A/B testing. In order to do this, varnish needs to show some people one version of the site (across all pages), and other people the alternative (across all pages), while the URL remains the same.
I was thinking of doing this by having varnish read a cookie containing a hash value, and show the user a different cached version based on that. I know Varnish can do that because I already do something similar for dealing with currencies.
Now the question is: I need to set this cookie value on the first page a visitor loads. I need to do it as efficiently as possible of course, and I don't want a page reload (otherwise I could have some javascript check if the cookie value is set, if not do an ajax call + page refresh or something).
How could I achieve this? Is it possible to have varnish check the cookie value, and if nothing is set yet (which should only happen on the first page a visitor visits) call a PHP API (which will determine which version to show to which type of people etc)? Varnish can then use this value, and proceed as if the cookie value was already there. The PHP API can write the returned value into a cookie for the next page load.
Alternatively: Is there a better way to get the behaviour I want?
Edit: Basically I'm looking for a way to set the cookie with a value generated by a PHP script (or command line command) without having to let the request hit the backend.