8

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?

N S
  • 2,524
  • 6
  • 32
  • 42
  • I use PHP-GDS (disclaimer: I am the author) and it will write to the built-in data store which you can access through the local admin interface. https://github.com/tomwalder/php-gds – Tom Jun 20 '17 at 01:23

2 Answers2

1

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.

see:

There are maybe two way to connect to local datasotre (I'm not tried with php):

  1. Use appengine-php-sdk for standard enviroment, start development server by dev_appserver.py, and view datastore from admin server viewer.

  2. Use google/cloud library for php, and set DATASTORE_EMULATOR_HOST env variable.

Unfortunately there isn't viewer for emulator, so I'm developing cli tool to check datastore entities by GQL: https://github.com/nshmura/dsio

nshmura
  • 5,940
  • 3
  • 27
  • 46
0

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 ... 
Felipe Valdes
  • 1,998
  • 15
  • 26