@amygdala
http://plus.google.com/+AmyUnruh

PHP on App Engine

In Preview, open signups!

Google Cloud Platform Starter Pack

Google Cloud Platform Starter Pack allows developers from affiliated partners to receive $2,000 of credit - $1,000 for Google App Engine and $1,000 for Cloud Platform services like Cloud SQL.

Apply at http://goo.gl/0YjkLQ

(cloud.google.com/starterpack)

Use promo code amyu-in.

WordPress on App Engine

Easy to deploy and manage your apps:

  • Scales automatically
  • Powerful background processing
  • Managed Cloud SQL
  • Managed services and APIs- preconfigured and ready to use
  • Security benefits

Roadmap

  • What is App Engine and the Cloud Platform?
  • Getting started with PHP on App Engine
  • WordPress on App Engine (walkthrough and demos)
  • if time... using Task Queues with WP

Google Cloud Platform


  • App Engine - PaaS
  • Cloud SQL - Stuctured Data
  • Cloud Storage - Object Store
  • Compute Engine - IaaS
  • Cloud Datastore - NoSQL datastore
  • BigQuery - fast big data analysis
  • ... and more

https://developers.google.com/cloud/

App Engine

PHP on App Engine

PHP on App Engine

github.com/GoogleCloudPlatform/appengine-php

http://php-minishell.appspot.com/phpinfo: Production phpinfo()

App Engine APIs and Services

Migrating a typical PHP app to App Engine

  • Create an AppEngine application, configure app.yaml and php.ini
  • Use http streams for network calls
  • Mail API for sending mail
  • Google Cloud SQL as production SQL database, Google Cloud Datastore for NoSQL datastore
  • Google Cloud Storage for file system writes/uploads (there is a GCS stream wrapper)
  • Memcache service for cache
  • Cron, task queues for background jobs

→ Scalable apps and asynchronous processing made easy

Walkthrough:
Let's put a WP app on App Engine

Set up the Cloud Platform components you're going to use

Set up your local development/testing enviroment

Configure your app

Portion of app.yaml file

  application: your-app-id
  version: one
  runtime: php
  api_version: 1

  handlers:
  - url: /(.*\.(htm$|html$|css$|js$))
    static_files: wordpress/\1
    upload: wordpress/(.*\.(htm$|html$|css$|js$))
    application_readable: true

  ...
  - url: /wp-admin/(.+)
    script: wordpress/wp-admin/\1
    secure: always

  - url: /wp-cron.php
    script: wordpress/wp-cron.php
    login: admin

  - url: /wp-(.+).php
    script: wordpress/wp-\1.php

  - url: /(.+)?/?
    script: wordpress/index.php      

Test locally, install plugins

A note about plugin installation...

<path_to_sdk>/dev_appserver.py --php_executable_path=<path_to_php-cgi54> .

Deploy!

  • via the launcher and appcfg.py
  • git push-to-deploy

Explore the App Engine Admin Console (dashboard, logs, task queues, versions and traffic splitting, and much more)

Resources

Google Cloud Platform Starter Pack

Google Cloud Platform Starter Pack allows developers from affiliated partners to receive $2,000 of credit - $1,000 for Google App Engine and $1,000 for Cloud Platform services including Cloud SQL.

Apply at http://goo.gl/0YjkLQ.
 

(cloud.google.com/starterpack)

Use promo code amyu-in.

App Engine Task Queues

  • Define tasks and process them asynchronously, in the background
  • App Engine automatically scales processing capacity
    • matches your queue configuration and processing volume.

Task Queues

Description

Adding A Task to a Queue

Tasks are HTTP request handlers.

require_once 'google/appengine/api/taskqueue/PushTask.php';
use \google\appengine\api\taskqueue\PushTask;
...
$task_params = ['message' => $message, 'to' => $people];
$task = new PushTask('/sms_notify.php', $task_params)->add();
$task->add(); 

A Task Handler

require_once 'google/appengine/api/taskqueue/PushTask.php';
use \google\appengine\api\taskqueue\PushTask;
...
$task_params = ['message' => $message, 'to' => $people];
$task = new PushTask('/sms_notify.php', $task_params)->add();
$task->add(); 

The /sms_notify handler script:

<?php
$message = $_POST['message'];
$to = $_POST['to'];
// in the handler, notify based on the params
// ....
  

Define the handler in your app.yaml file

handlers:
...
- url: /sms_notify
  script: sms_notify.php
  login: admin 
  • Task handlers are always run as 'admin'
  • You can use regexps in your app.yaml file, e.g.
- url: /(.+)_task
  script: /\1_task.php
  login: admin
    

Task Queues and WordPress hooks: made for each other

add_action('publish_post', 'launchNotificationTasks');
add_action('save_post', 'schedulePublishTask'); 

<Thank You!>