-
Notifications
You must be signed in to change notification settings - Fork 1k
PubSub example for PHP #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Google PubSub PHP Sample Application | ||
|
|
||
| ## Description | ||
|
|
||
| Note: The push endpoints don't work with the App Engine's local | ||
| devserver. The push notifications will go to an HTTP URL on the App | ||
| Engine server even when you run this sample locally. So we recommend | ||
| you deploy and run the app on App Engine. | ||
| TODO(tmatsuo): Better implementation for devserver. | ||
|
|
||
| ## Register your application | ||
|
|
||
| - Go to | ||
| [Google Developers Console](https://console.developers.google.com/project) | ||
| and create a new project. This will automatically enable an App | ||
| Engine application with the same ID as the project. | ||
|
|
||
| - Enable the "Google Cloud Pub/Sub" API under "APIs & auth > APIs." | ||
| - Enable the "Google Cloud Datastore" API under "APIs & auth > APIs." | ||
| - For local development also follow the instructions below. | ||
| - Go to "Credentials" and create a new Service Account. | ||
| - Select "Generate new JSON key", then download a new JSON file. | ||
| - Set the following environment variable: | ||
| - `GOOGLE_APPLICATION_CREDENTIALS`: the file path to the downloaded JSON file. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Install [`composer`](https://getcomposer.org) | ||
| - Install the App Engine Python SDK. | ||
| We recommend you install | ||
| [Cloud SDK](https://developers.google.com/cloud/sdk/) rather than | ||
| just installing App Engine SDK. | ||
|
|
||
| - Install Google API client library for PHP into 'lib' directory by running: | ||
|
|
||
| ``` | ||
| $ composer install | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Run the following commands to create your pubsub subscription topic: | ||
|
|
||
| ```sh | ||
| $ gcloud alpha pubsub topics create [your-topic-name] | ||
| 1 topic(s) created successfully | ||
| - projects/[your-project-name]/topics/[your-topic-name] | ||
| ``` | ||
|
|
||
| > We use **`php-pubsub-example`** as the topic name, but you can change this | ||
| > by setting the `PUBSUB_TOPIC` environment variable (see `app.yaml`) | ||
|
|
||
| Then you need to create your subscription to this topic by supplying | ||
| the endpoint to be notified when the topic is published to: | ||
|
|
||
| ``` | ||
| gcloud alpha pubsub subscriptions create [your-subscription-name] \ | ||
| --topic [your-topic-name] \ | ||
| --push-endpoint https://[your-project-name].appspot.com/receive_message \ | ||
| –-ack-deadline 30 | ||
| ``` | ||
|
|
||
| ## Deploy the application to App Engine | ||
|
|
||
| ``` | ||
| $ gcloud preview app deploy app.yaml --set-default --project YOUR_PROJECT_NAME | ||
| ``` | ||
|
|
||
| Then access the following URL: | ||
| https://{YOUR_PROJECT_NAME}.appspot.com/ | ||
|
|
||
| ## Run the application locally | ||
|
|
||
| ``` | ||
| $ dev_appserver.py -A your-project-name . | ||
| ``` | ||
|
|
||
| ## Contributing changes | ||
|
|
||
| * See [CONTRIBUTING.md](../CONTRIBUTING.md) | ||
|
|
||
| ## Licensing | ||
|
|
||
| * See [LICENSE](../LICENSE) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| runtime: php55 | ||
| api_version: 1 | ||
| threadsafe: true | ||
|
|
||
| handlers: | ||
| - url: /js | ||
| static_dir: web/js | ||
| - url: /.* | ||
| script: web/index.php | ||
|
|
||
| env_variables: | ||
| GOOGLE_PROJECT_NAME: "YOUR_PROJECT_NAME" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "autoload": { | ||
| "psr-4": { | ||
| "Google\\Cloud\\Samples\\Pubsub\\": "src" | ||
| } | ||
| }, | ||
| "require": { | ||
| "php": ">=5.4", | ||
| "silex/silex": "~1.3", | ||
| "twig/twig": "~1.8|~2.0", | ||
| "symfony/twig-bridge": "~2.7|3.0.*", | ||
| "google/apiclient": "~2.0@rc" | ||
| }, | ||
| "require-dev": { | ||
| "symfony/dom-crawler": "~2.0", | ||
| "symfony/css-selector": "~2.0", | ||
| "symfony/browser-kit": "~2.7" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the same string we call [your-project-id] above? Then we should probably call it YOUR_PROJECT_ID here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed everything to
your-project-nameinstead