Skip to content

Commit 14f1070

Browse files
Add README and config files for flexible/pubsub.
Also, remove the text describing how to create the topic and subscription, because that no happens automatically.
1 parent 74871e6 commit 14f1070

File tree

4 files changed

+77
-23
lines changed

4 files changed

+77
-23
lines changed

appengine/flexible/pubsub/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Google PubSub PHP Sample Application for App Engine Flexible Environment.
2+
3+
## Description
4+
5+
This sample demonstrates how to invoke PubSub from Google App Engine Flexible
6+
Environment.
7+
8+
The sample code lives in [a parent pubsub directory](../../../pubsub).
9+
Only two configuration files differ: `app.yaml` and `nginx-app.conf`.
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+
27+
## Configuration
28+
29+
- Edit `app.yaml`. Replace `your-google-project-id` with your google project id.
30+
31+
- Copy `app.yaml` and `nginx-app.conf` into [../../../pubsub](../../../pubsub). Ex:
32+
```sh
33+
~/gitrepos/php-docs-samples/appengine/flexible/pubsub$ cp -f app.yaml nginx-app.conf ../../../pubsub
34+
~/gitrepos/php-docs-samples/appengine/flexible/pubsub$ cd ../../../pubsub/
35+
~/gitrepos/php-docs-samples/pubsub$
36+
```
37+
38+
## Deploy the application to App Engine
39+
40+
```
41+
$ gcloud preview app deploy app.yaml --set-default --project YOUR_PROJECT_NAME
42+
```
43+
44+
Then access the following URL:
45+
https://{YOUR_PROJECT_NAME}.appspot.com/
46+
47+
## Run the application locally
48+
49+
```
50+
/usr/bin/php -S localhost:8910 -t web
51+
```
52+
53+
## Contributing changes
54+
55+
* See [CONTRIBUTING.md](../../../CONTRIBUTING.md)
56+
57+
## Licensing
58+
59+
* See [LICENSE](../../../LICENSE)
60+
61+

appengine/flexible/pubsub/app.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
runtime: php
2+
vm: true
3+
4+
runtime_config:
5+
document_root: web
6+
7+
env_variables:
8+
GOOGLE_PROJECT_NAME: your-google-project-id
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
location / {
2+
# try to serve file directly, fallback to front controller
3+
try_files $uri /index.php$is_args$args;
4+
}

pubsub/README.md

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,6 @@ TODO(tmatsuo): Better implementation for devserver.
3737
$ composer install
3838
```
3939

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-
6340
## Deploy the application to App Engine
6441

6542
```
@@ -69,6 +46,10 @@ $ gcloud preview app deploy app.yaml --set-default --project YOUR_PROJECT_NAME
6946
Then access the following URL:
7047
https://{YOUR_PROJECT_NAME}.appspot.com/
7148

49+
## Deploy the application to App Engine Flexible Environment.
50+
51+
See the instructions [here](../appengine/flexible/pubsub/README.md).
52+
7253
## Run the application locally
7354

7455
```

0 commit comments

Comments
 (0)