简体   繁体   中英

Session between servers in Google App Engine Flexible PHP environment

I've just moved my application to a Flexible PHP Google App Engine and quickly found out that sharing sessions between instances didn't work that good. Just refreshing a page showed different session results every time.

I've temporarily solved it by forcing my server in the app.yaml to only use one instance. But this instance is now heavily overloaded.

I've tried to find how solve the sessions between servers and the best info I've found is this: https://github.com/GoogleCloudPlatform/google-cloud-php-datastore/blob/master/DatastoreSessionHandler.php

Although it seems like I have to rewrite a lot of my own and 3rd party scripts if I have to make to edit all scripts where it saves to sessions.

Has anyone found a way of just changing the session handler and not have to change the scripts itself to just store sessions like $_SESSION['foo'] = 'asdf' ?

Many thanks

There are several options.

  1. Use client side cookies I haven't tested it yet, but google search gave me: https://github.com/dcro/php-secure-client-side-sessions

  2. Use database sessions. The following article is simple and easy to follow in my opinion: http://culttt.com/2013/02/04/how-to-save-php-sessions-to-a-database/

  3. Use datastore. For usage, see the comments in the php file: https://github.com/GoogleCloudPlatform/google-cloud-php/blob/master/src/Datastore/DatastoreSessionHandler.php

I am a bit late into the game, but I was looking for the same thing. Thanks a lot to Mr Matsuo (the accepted answer) for guiding us!

Here's a nice library which I've found, that provides a Datastore + Memcache alternative session handler. You can plug-it in and just call instead of "session_start". No further change of your scripts is necessary. https://github.com/tomwalder/php-gds-session

It uses behind the scenes another library by the same author ( https://github.com/tomwalder/php-gds ) and you'll need to configure the Datastore connection (with the credentials).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM