Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ before_install:
- php dump_credentials.php

script:
# run bigquery tests
- cd bigquery/api
- composer install
- phpunit mainTest.php
Expand All @@ -36,4 +37,9 @@ script:
- cd datastore
- composer install
- phpunit test
- cd ..
- cd ..
# run pubsub tests
- cd pubsub
- composer install
- phpunit test
- cd ..
2 changes: 1 addition & 1 deletion datastore/src/DatastoreHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DatastoreHelper

/**
* Creates a query object for pulling the last $limit number of
* "PubSubMessage" items, equivalent to the following GQL:
* "DatastoreComment" items, equivalent to the following GQL:
*
* SELECT * from DatastoreComment ORDER BY created DESC LIMIT 20
*
Expand Down
86 changes: 86 additions & 0 deletions pubsub/README.md
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
Copy link
Contributor

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.

Copy link
Contributor Author

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-name instead

```

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)


12 changes: 12 additions & 0 deletions pubsub/app.yaml
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"
19 changes: 19 additions & 0 deletions pubsub/composer.json
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"
}
}
Loading