Active PHP 7.2 sessions lost after gcloud app deploy

82 views
Skip to first unread message

Andy Whittle

unread,
Aug 16, 2019, 1:07:30 PM8/16/19
to Google App Engine
Hi

We switched to GAE PHP 7.2 runtime a couple of months ago.

I can't say for definite, but I'm fairly sure that on the PHP 5.5 runtime, active user sessions continued running without hitch when we deployed a new version of our app.

Since we switched to PHP 7.2, users are getting kicked out of the app the moment 'gcloud app deploy' has completed.

Does anybody know how we can prevent this from happening, please, as we're getting complaints from the users who are logged into the QA version each time we have to push a small hotfix, which can sometimes be several times per day.

Thanks

George (Cloud Platform Support)

unread,
Aug 16, 2019, 4:22:39 PM8/16/19
to Google App Engine
This is expected behavior.  If you deploy a version that specifies the same version ID as a version that already exists on App Engine, the files that you deploy will overwrite the existing version. This can be problematic if the version is serving traffic because traffic to your application might be disrupted. You can avoid disrupting traffic if you deploy your new version with a different version ID and then move traffic to that version. Related detail is offered on the "Deploying a PHP 5 App" documentation page

Andy Whittle

unread,
Aug 19, 2019, 12:58:38 PM8/19/19
to Google App Engine
Thanks, George. We already increment the version deployed each time, but this still occurs.

Can you tell me where I'm going wrong in the deployment process, please?

Example:

- Current version with 100% traffic is named "v123" with active users.
- gcloud app deploy -v v124
- Traffic is automatically sent to v124, at which point the users are kicked out.

Is there a step I'm missing, please? Thanks

Jason Collins

unread,
Aug 19, 2019, 9:40:24 PM8/19/19
to Google App Engine
How are you storing your sessions? Is it the /tmp folder default, or have you used something like MySQL (Cloud SQL) to store sessions?

George (Cloud Platform Support)

unread,
Aug 20, 2019, 1:20:13 PM8/20/19
to Google App Engine
In App Engine Standard environment, you can migrate traffic gradually. "Migrating Traffic" page gives details. Gradual traffic migration traffic between versions running in the flexible environment is not supported. You must migrate traffic immediately to versions that are running in the flexible environment.

Andy Whittle

unread,
Aug 21, 2019, 5:10:53 AM8/21/19
to Google App Engine
Hi Jason,

We're using whichever method GAE Standard env provides to store sessions.

Jason Collins

unread,
Aug 21, 2019, 1:47:38 PM8/21/19
to Google App Engine
In GAE Std, for php72, the default session store is configured. This default is `session.save_handler=files` which uses /tmp to store session files.

In GAE Std, each instance has its own /tmp and the /tmp is empty on any cold start. So this is not really a viable option for session storage (e.g., different requests from the same user may land on different instances, and thus different sessions).

You can use php.ini to configure an alternative (e.g., MySQL on Cloud SQL, or Cloud Memorystore), but you need to do some set up work (e.g., create a Cloud SQL instance, configure access).

We need to have better documentation about this; I will create an internal bug to have some created.

Brent Shaffer

unread,
Aug 22, 2019, 1:39:36 PM8/22/19
to Google App Engine
You can also use Firestore for sessions, which I've serendipitously just added to the client library. I think this is the best way because 
  1. There is a free tier
  2. It's very simple to set up compared to a MySQL instance (no need to set up a database/username/password).
  3. It's more "serverless" e.g. you don't configure instances.
I have a "getting started" tutorial for using sessions w/ App Engine and Firestore. It'll be at /php/getting-started/sessions, so we can add it to the appengine navigation. Check out the code here.

- Brent

Andy Whittle

unread,
Sep 3, 2019, 9:16:27 AM9/3/19
to Google App Engine
Thanks Jason / Brent,

We've already got a Cloud SQL instance, so not much of a support overhead for us to add a session storage DB.

In regards to security and performance, do you have any comments or advice re. Cloud SQL vs. Cloud Memorystore vs Firestore, please?  I'm unsure which would be the best method on balance.

Andy Whittle

unread,
Sep 3, 2019, 9:31:19 AM9/3/19
to Google App Engine
Brent - do you have a copy of the getting-started/sessions doc you can share, please, as I can't see it posted publicly yet?

Cheers
Reply all
Reply to author
Forward
0 new messages