What is the best way to develop locally in PHP and the Google datastore?
The dev_appserver.py docs say I can view local datastore entities, but there is no documentation on how to connect/write to this local datastore using PHP.
I can write to the local datastore emulator using:
// Start emulator: gcloud beta emulators datastore start --data-dir=_datastore // Pointing this to dev_appserver's 'API server' doesn't work. putenv('DATASTORE_EMULATOR_HOST=http://localhost:8081'); $datastore = $cloud->datastore();
But these entities do not show up in dev_appserver.py’s local admin server at http://localhost:8000/datastore.
Even setting the dev_appserver’s
--datastore_path to be equal to the emulator’s
--data-dir does nothing.
Why are the datastore emulator and dev_appserver.py’s datastore different? They share the same name and the docs refer to them interchangeably. This is frustrating.
Is this the correct way to do local datastore development? Is there a way to write to the local datastore and have the entities show up in the admin server viewer?
Google Cloud Datastore Emulator and dev_appserver.py have different underlying storage.
So the entities on datastore emulator cannot be shown in the admin server viewer.
There are maybe two way to connect to local datasotre (I’m not tried with php):
Use appengine-php-sdk for standard enviroment, start development server by dev_appserver.py, and view datastore from admin server viewer.
Use google/cloud library for php, and set
Unfortunately there isn’t viewer for emulator, so I’m developing cli tool to check datastore entities by GQL: https://github.com/nshmura/dsio
have u tried passing the environment variables to the php executable before including the libraries?
maybe try this:
#/bin/sh export DATASTORE_EMULATOR_HOST=http://localhost:8081 dev_appserver.py ...