How to connect Google App Engine (PHP) with Cloud Datastore? - php

I am trying to connect my Local Development Site (using PHP) to Cloud Datastore, but unfortunately I do not know how to set up my code to reach the Datastore. I have tried the solution of tomwalder/php-gds, but I do not know, how to set up the code to work with my site. After the installation with composer, I do not know which file should be modified, there is no config.php in my directory. There are also no Google Documentation about Datastore for PHP.
I am open for any solution to connect the Datastore with my site.
Can you please give us a few tips, how to start the work?

I'd suggest taking a look at https://github.com/tomwalder/php-gds. Tom just released a version that connects natively to the datastore, which is faster than going via Cloud Datastore.

Related

Managing the Azure Windows through PHP SDk

I am trying to configure the php sdk for managing the azure instance to perform basic operations like starting or stopping a VM,getting the IP of running VM,etc.I tried searching but didnt find any document.Is there any document available ? Also how to establish client session for the same ?
As far as I know, there is no SDK for PHP we can use to manage Azure VM at the present time. The REST Management API is the one you want to go for.
Reference:
Virtual Machines REST API

How to write to local App Engine datastore with PHP

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.
see:
https://github.com/GoogleCloudPlatform/google-cloud-datastore/issues/21
Connecting to AppEngine datastore in development via Cloud Datastore API
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 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
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 ...

PHP stream wrapper for Google Cloud Storage

I am in a process of setting up Prestashop installation in a cluster of 3 GCE instances, managed by Kubernetes. I use Cloud SQL as DB and all seems to be running well, except, of course the images part, since prestashop in each pod uploads and shows images to/from it's local filesystem.
In App Engine I cloud use stream_context_set_default() and that would allow me to use "gs://mybucket" as a regular path. Is there a way to do that in Compute Engine? If it is possible, making Prestashop use Cloud Storage bucket can be done in 2 lines of code.
There is a StreamWrapper for Amazon S3 service that does exactly what I need: http://hiousi.tumblr.com/post/94824087894/prestashop-images-hosted-on-amazon-s3
But I would like to use Cloud Storage.
The source code for the stream wrapper can be downloaded at https://github.com/GoogleCloudPlatform/appengine-php-sdk/tree/master/google/appengine/ext/cloud_storage_streams.
It has a couple of dependencies on other GAE APIs such as App Identity & Urlfetch. They may need to be stubbed out or replaced by equivalent services on GCE.
i have created a PHP StreamWrapper for Google Compute Engine, if you're still interested. Here is the link to my adapted version.
https://github.com/jimyaghi/GCECloudStorageStreamWrapper
Sorry it's not more friendly, but it's a good useful bit of work. i'm using it and it works great.

Can I connect Google Cloud SQL from PHP application Hosted in App Engine?

I think I can, But I read a FAQ form cloud sql page, as follows,
Q. Can I use languages other than Java or Python?
A. Only Java and Python are supported for Google Cloud SQL.
What is it supposed to mean? What are they referring to? Can't I use cloud SQL for my PHP app?
I have another question, (I'm so naive to cloud app engine)
I'm developing a PHP application locally, thought of upload it finally to google app engine. Is there any way of doing it locally connect Cloud SQL? So that I could make sure. Otherwise It's hard to update uploaded application thousands of times per day during development. Hope you understood my question.
Yes you can. See the documentation here for PHP and Cloud SQL:
https://developers.google.com/appengine/docs/php/cloud-sql/
As for local development, you need to get an IP Address for your Cloud SQL instance, which is a paying feature.
What I also suggest is that you install a local MySQL instance on your development workstation, it's far easier. Just make sure to update your db settings before deploying your application to App Engine in order to switch to your Cloud SQL instance.

Different database for GAE

How to use another database for Google App engine than the datastore. And if it could be possible to access it with php(quercus).
Not in practical terms. Datastore is the only supported database at the moment.
You could have a database on another server and access it via RPC (REST, WebService), but this would not be an integrated approach and would add more work to the project. For example you could set up a MySql server somewhere and use phprestsql to setup a REST interface and then acces it from GAE.
#Peter Knego
i am also looking for same. I want to host my java web application on GAE and databse on different Server(Godaddy).
Google data store is free for only 6 months, So i would like to use database of different hosting(goDaddy). So is it possibe??
I am able to use database of my hosting(goDaddy) from my local system but when i upload my application to GAE that it doesn't work. I know it is possible in case of other servers but what about GAE.

Categories