CloudFoundry PHP example application: pgbouncer
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.bp-config
.extensions/pgbouncer
vendor
README.md
index.php
manifest.yml

README.md

CloudFoundry PHP Example Application: pgbouncer

This is an example application which also runs pgbouncer for Postgres connection pooling.

This is an example of how it's possible to package an extension with your application to run an additional process in the background. In this case, we package pgbouncer but you could adjust the example to run one or more a different process.

Usage

  1. Clone the app (i.e. this repo).
git clone https://github.com/cloudfoundry-samples/cf-ex-pgbouncer
cd cf-ex-pgbouncer
  1. If you don't have one already, create a Postgres service. With Pivotal Web Services, the following command will create a free Postgres database through ElephantSQL.
cf create-service elephantsql turtle pgsql
  1. Push it to CloudFoundry.
cf push

Access your application URL in the browser. The output should list each service bound to the application and the results of connecting (pg_connect) & pinging (pg_ping) the service.

  1. If there are any problems, you can run the following command to get more information.
cf logs --recent cf-ex-pgbouncer

How It Works

When you push the application here's what happens.

  1. The local bits are pushed to your target. This includes the pgbouncer binary, which this example does because it's small. If you had a larger binary, the extension could download this from somewhere and extract it during the compile phase to make pushing the application faster.
  2. The server downloads the PHP Buildpack and runs it. This installs HTTPD and PHP.
  3. The build pack sees the custom extension that we pushed and runs it. The extension configures pgbouncer based on VCAP_SERVICES. If you don't want this automatic configuration, you can manually specify database configurations in the included pgbouncer.ini file. The extension also instructs the build pack to run and monitor the pgbouncer process.
  4. At this point, the build pack is done and CF runs our droplet. This includes HTTPD, PHP & pgbouncer.

Caution

This example application configures pgbouncer so that it works. This does not necessarily mean it's the best configuration or that it's a secure configuration. You should absolutely audit the configuration and adjust as necessary for your application.

Suggestions for improvements or PR's to the example are welcome as well.