Hopefully I understood your question right. I don't really see how PHPSESSID is related to handling the 503 errors, but you don't need to use cookies at all to re-try a request.
You can use restarts in Varnish to accomplish what you are trying to do. For instance to try the request 2 times you could do:
sub vcl_error {
if (obj.status == 503 && req.restarts < 2) {
return (restart);
}
}
This should provide the functionality you are looking for without touching the cookies.
This is obvious, but I will say it anyway: what you really should do is find out what is causing the 503 errors. If they are not coming from the backend, they are caused either by timeouts or a problem with the Varnish configuration. Keep an eye on your Varnish log for "TxStatus c 503" lines and see what's going on with the requests.
Update regarding the possible cause of 503 errors:
Apparently you are receiving the 503 errors on POST requests (i.e. when a user tries to log in). This can occur if posts are done over slow links or the connection is terminated by the client for some other reason before POST body is completely transferred. However this should not show up as no error recorded
in varnishlog. You might want to give the following a shot in any case to see if it fixes your problem.
Varnish defaults to return(pass) for POST requests, but this doesn't work as expected in all cases (see Varnish ticket #849 for more information).
We have opted to pipe all POST requests and append X-Forwarded-For to the requests as well. Here's the relevant VCL:
# PIPE all POST requests
sub vcl_recv {
if (req.request == "POST") {
return (pipe);
}
}
# Set XFF for piped requests
sub vcl_pipe {
set bereq.http.Connection = "close";
set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
if (bereq.http.x-forwarded-for) {
set bereq.http.X-Forwarded-For = bereq.http.X-Forwarded-For + ", " + client.ip;
} else {
set bereq.http.X-Forwarded-For = client.ip;
}
return (pipe);
}