Skip to content

Commit f003fca

Browse files
committed
fix style, use hostname for choosing tcp mode, add GAE standard docs
1 parent abd5c73 commit f003fca

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

cloud_sql/postgres/pdo/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@ Next, the following command will deploy the application to your Google Cloud pro
7979
```bash
8080
$ gcloud beta app deploy
8181
```
82+
83+
## Google App Engine Standard
84+
85+
To run on GAE-Standard, create an App Engine project by following the setup for these [instructions](https://cloud.google.com/appengine/docs/standard/php7/quickstart#before-you-begin).
86+
87+
First, update `app-standard.yaml` with the correct values to pass the environment variables into the runtime.
88+
89+
Next, the following command will deploy the application to your Google Cloud project:
90+
91+
```bash
92+
$ gcloud app deploy app-standard.yaml
93+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
runtime: php72
16+
17+
# Remember - storing secrets in plaintext is potentially unsafe. Consider using
18+
# something like https://cloud.google.com/kms/ to help keep secrets secret.
19+
env_variables:
20+
CLOUD_SQL_CONNECTION_NAME: ::
21+
DB_USER: my-db-user
22+
DB_PASS: my-db-pass
23+
DB_NAME: my-db
24+
25+
# Defaults to "serve index.php" and "serve public/index.php". Can be used to
26+
# serve a custom PHP front controller (e.g. "serve backend/index.php") or to
27+
# run a long-running PHP script as a worker process (e.g. "php worker.php").
28+
#
29+
# entrypoint: serve index.php

cloud_sql/postgres/pdo/src/app.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
$username = getenv('DB_USER');
3939
$password = getenv('DB_PASS');
4040
$dbName = getenv('DB_NAME');
41-
$hostname = getenv('DB_HOSTNAME') ?: '127.0.0.1';
41+
$hostname = getenv('DB_HOSTNAME');
4242
$cloud_sql_connection_name = getenv('CLOUD_SQL_CONNECTION_NAME');
4343

4444
try {
@@ -49,16 +49,16 @@
4949
// // $cloud_sql_connection_name = getenv("CLOUD_SQL_CONNECTION_NAME");
5050
// // $hostname = "127.0.0.1"; // Only used in TCP mode.
5151

52-
if ($cloud_sql_connection_name) {
52+
if ($hostname) {
53+
// Connect using TCP
54+
$dsn = sprintf('pgsql:dbname=%s;host=%s', $dbName, $hostname);
55+
} else {
5356
// Connect using UNIX sockets
5457
$dsn = sprintf(
5558
'pgsql:dbname=%s;host=/cloudsql/%s',
5659
$dbName,
5760
$cloud_sql_connection_name
5861
);
59-
} else {
60-
// Connect using TCP
61-
$dsn = sprintf('pgsql:dbname=%s;host=%s', $dbName, $hostname);
6262
}
6363

6464
// Connect to the database.
@@ -100,7 +100,7 @@
100100
};
101101

102102
// Configure the templating engine.
103-
$container['view'] = function() {
103+
$container['view'] = function () {
104104
return Twig::create(__DIR__ . '/../views');
105105
};
106106

0 commit comments

Comments
 (0)