Slide 1

Slide 1 text

12-Factor cakephp applications i’ll tell you hwat

Slide 2

Slide 2 text

cakefest 2013 12 factor cakephp applications About me Cakephp core seatgeek employee accidental operations all around good guy

Slide 3

Slide 3 text

cakefest 2013 12 factor cakephp applications a common problem ‣ supporting more requests ‣ configuration ‣ dependency management ‣ installing the codebase ‣ logging ‣ background tasks

Slide 4

Slide 4 text

cakefest 2013 12 factor cakephp applications building scalable applications codebase

Slide 5

Slide 5 text

use version control cakefest 2013 12 factor cakephp applications git init

Slide 6

Slide 6 text

one codebase, multiple deploys cakefest 2013 SEATGEEEK GOALS deploy staging deploy prod

Slide 7

Slide 7 text

cakefest 2013 12 factor cakephp applications building scalable applications Dependencies

Slide 8

Slide 8 text

use composer cakefest 2013 12 factor cakephp applications composer update

Slide 9

Slide 9 text

private dependencies? cakefest 2013 12 factor cakephp applications satis

Slide 10

Slide 10 text

cakefest 2013 12 factor cakephp applications building scalable applications configuration

Slide 11

Slide 11 text

environment variables cakefest 2013 12 factor cakephp applications SetEnv DEBUG 0

Slide 12

Slide 12 text

USING ENV VARS IN PHP cakefest 2013 12 factor cakephp applications $DEBUG = getenv(‘DEBUG’);

Slide 13

Slide 13 text

cakefest 2013 12 factor cakephp applications building scalable applications BACKING SERVICES

Slide 14

Slide 14 text

cakefest 2013 12 factor cakephp applications PARSING RESOURCES

Slide 15

Slide 15 text

cakefest 2013 12 factor cakephp applications false, 'prefix' => '', 'encoding' => 'utf8', ); public function __construct() { $DATABASE_URL = parse_url(getenv('DATABASE_URL')); $this->default['datasource'] => 'Database/Mysql'; $this->default['host'] => Hash::get($DATABASE_URL, 'host'); $this->default['login'] => Hash::get($DATABASE_URL, 'user'); $this->default['password'] => Hash::get($DATABASE_URL, 'pass'); $this->default['database'] => substr(Hash::get($DATABASE_URL, 'path'), 1); } }

Slide 16

Slide 16 text

cakefest 2013 12 factor cakephp applications building scalable applications BUILD, RELEASE, RUN

Slide 17

Slide 17 text

BUILD STEP cakefest 2013 12 factor cakephp applications PACKAGE ALL THE THINGS

Slide 18

Slide 18 text

CREATE A RELEASE cakefest 2013 12 factor cakephp applications TAR AND DEPLOY

Slide 19

Slide 19 text

RUN cakefest 2013 12 factor cakephp applications RESTART PROCESSES CLEAR CACHE

Slide 20

Slide 20 text

cakefest 2013 12 factor cakephp applications building scalable applications process

Slide 21

Slide 21 text

stateless cakefest 2013 12 factor cakephp applications Configure::write('Session', array( 'defaults' => 'cache', 'handler' => array( 'config' => 'memcache_sessions' ) ));

Slide 22

Slide 22 text

cakefest 2013 12 factor cakephp applications building scalable applications port binding

Slide 23

Slide 23 text

php port binding cakefest 2013 12 factor cakephp applications SERVER BECOMES A DEPENDENCY

Slide 24

Slide 24 text

cakefest 2013 12 factor cakephp applications building scalable applications CONCURRENCY

Slide 25

Slide 25 text

NO MORE WEBCRONS cakefest 2013 12 factor cakephp applications - Need to send an email? - Cache a large dataset in the database? - Generate reports for Bill in accounting?

Slide 26

Slide 26 text

background processing cakefest 2013 12 factor cakephp applications kamisama/cake-resque josegonzalez/cake_djjob

Slide 27

Slide 27 text

cakefest 2013 12 factor cakephp applications building scalable applications dev/prod parity

Slide 28

Slide 28 text

cakefest 2013 12 factor cakephp applications run tests in the same environment

Slide 29

Slide 29 text

mysql in dev, mysql in prod cakefest 2013 12 factor cakephp applications vagrantup.com

Slide 30

Slide 30 text

cakefest 2013 12 factor cakephp applications building scalable applications logs

Slide 31

Slide 31 text

cakelog cakefest 2013 12 factor cakephp applications CakeLog::config('default', array( 'engine' => 'ConsoleLog', 'stream' => new ConsoleOutput('php://stdout') ));

Slide 32

Slide 32 text

cakefest 2013 12 factor cakephp applications logging format ‣ UTC tiMESTAMP, ISO8601 ‣ REQUEST DATA ‣ UNIQUE REQUEST ID ‣ USER IDENTIFIER ‣ THE MESSAGE ITSELF

Slide 33

Slide 33 text

cakefest 2013 12 factor cakephp applications building scalable applications admin processes

Slide 34

Slide 34 text

cakeshell cakefest 2013 12 factor cakephp applications Console/cake Migrations.migration run all

Slide 35

Slide 35 text

repl cakefest 2013 12 factor cakephp applications brew install Boris wget -O boris.php http://bit.ly/1dURtFw mv boris.php app/Console/boris.php php app/Console/boris.php

Slide 36

Slide 36 text

cakefest 2013 12 factor cakephp applications build better apps ‣ reduce developer friction ‣ higher scalability ‣ increase portability ‣ decrease management overhead

Slide 37

Slide 37 text

developer love thanks cakefest 2013 12 factor cakephp applications