How to write to local App Engine datastore with PHP

Viewed 399

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?

2 Answers
Related