30
on App Engine PHP by Luis Atencio 7/10/13

PHP on Google App Engine

Embed Size (px)

DESCRIPTION

At Google IO this year, Google announced support for a new runtime running on App Engine, PHP. Currently, they have full support for languages such as Python, Java, and Go. PHP on App Engine was the number one request voted by developers and Google has finally delivered. PHP empowers a great percentage of the web sites in the world, it is very likely this will be taken out of Experimental mode soon into full Production mode. Google has taken the open source PHP 5.4 platform and augmented it to run on App Engine. They created a safe "sandboxed" environment for your apps. A match made in heaven? PHP is an inherent scalable language. It's thread-safe and stateless nature, makes an ideal candidate to run on scalable, elastic infrastructure. PHP allows you to code rapidly and App Engine allows you to deploy rapidly, the combination makes an incomparable development platform. Since Google is implementing PHP 5.4, their PHP runtime has the built-in extensions for APC, OpenSSL, OAuth, among others. APC is an essential component to any PHP installation, so it's ideal that they jumped the gun and started with PHP 5.4 and 5.3.*. What this means for PHP developers? For a number of years now (since 2008), Java developers have enjoyed and exploited the power of Google's cloud to create their own applications. This is the same infrastructure that Google uses to contain their own applications and tools, so it's proven to be super scalable and reliable. App Engine falls into the category of Platform-As-A-Service (PaaS) that, coupled with great tools, endows your development environment with great agility. Now, PHP developers can take advantage of this.

Citation preview

Page 1: PHP on Google App Engine

on App Engine

PHP

byLuis Atencio7/10/13

Page 2: PHP on Google App Engine

Outline

• Intro– Overview– Match made in heaven– What this means for PHP developers– Environment– Drawbacks– Installation– Project Structure

•Storage

•Services

•Demos

Page 3: PHP on Google App Engine

Intro

Page 4: PHP on Google App Engine

Overview

• It is a platform for developing web applications hosted on Google managed data centers

•Scalable, distributed, elastic PaaS

•PHP support was announced at Google IO 2013

•Limited Preview

•Most voted App Engine ticket by developers

•Alternatives:– Create a new JVM language– Use Caucho Quercus– Implement and extend the Open Source PHP core

Page 5: PHP on Google App Engine

Match Made in Heaven

•PHP inherently scalable

•Thread-safe

•Stateless

•PHP allows you to code (prototype) rapidly

•App Engine allows you to deploy rapidly

•Google’s PHP CGI has support for APC cache, OpenSSL, OAuth, Memcache, and many more extensions

Page 6: PHP on Google App Engine

What this means for PHP Developers

•For Java developers since 2008

•Proven, reliable, and super scalable infrastructure

•Same infrastructure that Google uses for their own apps

•Another PaaS in the market (CloudFoundary, Heroku, etc)

•Cloud SQL (MySQL)

•PHPStorm support for GAE

Page 7: PHP on Google App Engine

PHP allows you to code rapidly, App Engine allows you to deploy

rapidly

Page 8: PHP on Google App Engine
Page 9: PHP on Google App Engine

Architecture

Page 10: PHP on Google App Engine

Environment

Note: you can provide your own php.ini and overwrite certain values

PHP 5.8.4 runtime

APC bcmath json gd ereg dom

date ctypefunctions PDO mcrypt openSSL SOAP

SPL memcache memcached gcs simplexml url_fetch

Page 11: PHP on Google App Engine

Stream Wrappers

•Used extensibly in App Engine to overload communication protocols

•Allows you to use native PHP functions such as fopen( ) and fread( )

•Built in with App Engine:

Protocol Description

http URL Fetch Service

https:// Secure URL Fetch Service

gs:// Read/write GCS

Page 12: PHP on Google App Engine

Installation

•Python 2.7– Used by the SDK’s runtime

•PHP 5.4.8 GGI with extensions

•App Engine PHP 1.8.1 SDK– Contains scripts for running a local version of GAE (dev_appserver.py)– Contains scripts for managing your instances in production (appcfy.py)

•MySQL 5.5

Page 13: PHP on Google App Engine

Project Structure

•Source files [/src]

•Static resources [.css, .js, .png]

• [optional] PHP.ini file

• [required] YAML file for configuration management– YAML Ain’t Markup Language– Alternative to configuration management for App Engine (appengine-web.xml, queue.xml,

cron.xml)– Human friendly data serialization standard for programming languages

•Basic Usage:– http://en.wikipedia.org/wiki/YAML#Language_elements

Page 14: PHP on Google App Engine

Storage

Cloud StorageCloud SQL

Page 15: PHP on Google App Engine

Cloud SQL [doc]

•Experimental Mode

•Out-of-the-box MySQL 5.5.31

•Automatic Backups (daily)

•Geo-located with your application

•Replicated across datacenters

SQL

Page 16: PHP on Google App Engine

Storage

Cloud StorageCloud SQL

Page 17: PHP on Google App Engine

Cloud Storage [doc]

•Experimental Mode

•Emulation of a file system in the cloud with automatic backups

•This is the file system your application will interact with

•With built in stream wrappers, access is seamless

Storage

Page 18: PHP on Google App Engine

ServicesLogs Mail Memcache URL Fetch

Users Task Queues

Page 19: PHP on Google App Engine

Logs [doc]

•Overridden of the syslog( ) native function

•Logs redirected to App Engine’s rolling log implementation

•Logs can be configured in the admin console, and downloaded with SDK tools

Page 20: PHP on Google App Engine

Mail [doc]

•App Engine allows you to send mail with attachements

•Overriden the mail( ) function to be directed to their MailService call

•Configure a user in your application to send make from

• In local development mode, mail( ) call prints the mail text to the logs

Page 21: PHP on Google App Engine

Memcache [doc]

•Uses a distributed, scalable, in-memory caching technology

•Very effective for query caching and object state sharing (up to 1 MB)

•App Engine uses it for session management

Page 22: PHP on Google App Engine

URL Fetch [doc]

•Used to communicate with other applications or restful services

•HTTP/1.1 compliant

•Requests are made using the overloaded stream wrappers for http and https

•Use native PHP calls such as file_get_contents( )

•Response size can be up to 32MB

Page 23: PHP on Google App Engine

Users [doc]

•Detect signed in Google users or any OpenID identifier

•User properties such as admin role, first name, last name, email, nickname, etc

•Specially useful if your application belongs to the Google marketplace

Page 24: PHP on Google App Engine

Task Queues [doc]

•Perform asynchronous, parallel work outside of the scope of the request

•Follows the “web hooks” and “unit of work” patterns

•App Engine allows Task queues to execute for 10 minutes

•Configured via a file called queue.yaml: name, retry limits, concurrent execution limit, etc

Page 25: PHP on Google App Engine

Drawbacks of App Engine

•PHP functions and system calls blacklisted, e.g. exec(), system()

•Access to file system is prohibited

•Direct socket creation is prohibited

•Support for outbound sockets disabled

•Request/response cannot exceed 60 sec

•You cannot stream data within a single request

•Pure PHP: you cannot compile and upload your own extensions

Page 26: PHP on Google App Engine

Uploading your Application

•You must have a Google account and request your Google account to be whitelisted

•You need to create a GAE application ID and request Google to whitelist your application here:

https://gaeforphp.appspot.com/

•Using the SDK (appcfy.py) you will be able to upload and manage your instances in production

•Source-to-Push deployment via Git

Page 27: PHP on Google App Engine
Page 28: PHP on Google App Engine

•With minimal configuration, WordPress runs on App Engine seamlessly– One caveat, no dynamic updating of plugins and core

•Concrete5 and Drupal also known to run on App Engine

CMS on App Engine

Page 29: PHP on Google App Engine

Stuff to look at

•https://developers.google.com/appengine/docs/php/

•http://www.youtube.com/watch?v=Qt1_atU_Qsg

•http://php-minishell.appspot.com/

•http://stackoverflow.com/questions/tagged/google-app-engine+php

•https://developers.google.com/appengine/articles/wordpress

•https://moodle.org/mod/forum/discuss.php?d=228830

•https://developers.google.com/appengine/docs/php/refdocs/

•http://blog.jetbrains.com/phpstorm/2013/05/support-for-google-app-engine-php-in-phpstorm/

•http://blog.boombatower.com/drupal-google-app-engine

Page 30: PHP on Google App Engine

Next meeting:

South Florida PHP User Group

07/17/1013

Miami