|
| 1 | +# Google PubSub PHP Sample Application |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +Note: The push endpoints don't work with the App Engine's local |
| 6 | +devserver. The push notifications will go to an HTTP URL on the App |
| 7 | +Engine server even when you run this sample locally. So we recommend |
| 8 | +you deploy and run the app on App Engine. |
| 9 | +TODO(tmatsuo): Better implementation for devserver. |
| 10 | + |
| 11 | +## Register your application |
| 12 | + |
| 13 | +- Go to |
| 14 | + [Google Developers Console](https://console.developers.google.com/project) |
| 15 | + and create a new project. This will automatically enable an App |
| 16 | + Engine application with the same ID as the project. |
| 17 | + |
| 18 | +- Enable the "Google Cloud Pub/Sub" API under "APIs & auth > APIs." |
| 19 | +- Enable the "Google Cloud Datastore" API under "APIs & auth > APIs." |
| 20 | +- For local development also follow the instructions below. |
| 21 | + - Go to "Credentials" and create a new Service Account. |
| 22 | + - Select "Generate new JSON key", then download a new JSON file. |
| 23 | + - Set the following environment variable: |
| 24 | + - `GOOGLE_APPLICATION_CREDENTIALS`: the file path to the downloaded JSON file. |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +- Install [`composer`](https://getcomposer.org) |
| 29 | +- Install the App Engine Python SDK. |
| 30 | + We recommend you install |
| 31 | + [Cloud SDK](https://developers.google.com/cloud/sdk/) rather than |
| 32 | + just installing App Engine SDK. |
| 33 | + |
| 34 | +- Install Google API client library for PHP into 'lib' directory by running: |
| 35 | + |
| 36 | +``` |
| 37 | +$ composer install |
| 38 | +``` |
| 39 | + |
| 40 | +## Configuration |
| 41 | + |
| 42 | +Run the following commands to create your pubsub subscription topic: |
| 43 | + |
| 44 | +```sh |
| 45 | +$ gcloud alpha pubsub topics create [your-topic-name] |
| 46 | +1 topic(s) created successfully |
| 47 | + - projects/[your-project-name]/topics/[your-topic-name] |
| 48 | +``` |
| 49 | + |
| 50 | +> We use **`php-pubsub-example`** as the topic name, but you can change this |
| 51 | +> by setting the `PUBSUB_TOPIC` environment variable (see `app.yaml`) |
| 52 | +
|
| 53 | +Then you need to create your subscription to this topic by supplying |
| 54 | +the endpoint to be notified when the topic is published to: |
| 55 | + |
| 56 | +``` |
| 57 | +gcloud alpha pubsub subscriptions create [your-subscription-name] \ |
| 58 | + --topic [your-topic-name] \ |
| 59 | + --push-endpoint https://[your-project-name].appspot.com/receive_message \ |
| 60 | + –-ack-deadline 30 |
| 61 | +``` |
| 62 | + |
| 63 | +## Deploy the application to App Engine |
| 64 | + |
| 65 | +``` |
| 66 | +$ gcloud preview app deploy app.yaml --set-default --project YOUR_PROJECT_NAME |
| 67 | +``` |
| 68 | + |
| 69 | +Then access the following URL: |
| 70 | + https://{YOUR_PROJECT_NAME}.appspot.com/ |
| 71 | + |
| 72 | +## Run the application locally |
| 73 | + |
| 74 | +``` |
| 75 | +$ dev_appserver.py -A your-project-name . |
| 76 | +``` |
| 77 | + |
| 78 | +## Contributing changes |
| 79 | + |
| 80 | +* See [CONTRIBUTING.md](../CONTRIBUTING.md) |
| 81 | + |
| 82 | +## Licensing |
| 83 | + |
| 84 | +* See [LICENSE](../LICENSE) |
| 85 | + |
| 86 | + |
0 commit comments