Upgrade to Pro — share decks privately, control downloads, hide ads and more …

12 Factor CakePHP Applications

12 Factor CakePHP Applications

A brief overview of what 12 factor applications are and how to best apply those principles to CakePHP Applications.

Jose Diaz-Gonzalez

September 01, 2013
Tweet

More Decks by Jose Diaz-Gonzalez

Other Decks in Technology

Transcript

  1. cakefest 2013 12 factor cakephp applications About me Cakephp core

    seatgeek employee accidental operations all around good guy
  2. cakefest 2013 12 factor cakephp applications a common problem ‣

    supporting more requests ‣ configuration ‣ dependency management ‣ installing the codebase ‣ logging ‣ background tasks
  3. USING ENV VARS IN PHP cakefest 2013 12 factor cakephp

    applications $DEBUG = getenv(‘DEBUG’);
  4. cakefest 2013 12 factor cakephp applications <?php class DATABASE_CONFIG {

    public $default = array( 'persistent' => 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); } }
  5. stateless cakefest 2013 12 factor cakephp applications Configure::write('Session', array( 'defaults'

    => 'cache', 'handler' => array( 'config' => 'memcache_sessions' ) ));
  6. 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?
  7. mysql in dev, mysql in prod cakefest 2013 12 factor

    cakephp applications vagrantup.com
  8. cakelog cakefest 2013 12 factor cakephp applications CakeLog::config('default', array( 'engine'

    => 'ConsoleLog', 'stream' => new ConsoleOutput('php://stdout') ));
  9. cakefest 2013 12 factor cakephp applications logging format ‣ UTC

    tiMESTAMP, ISO8601 ‣ REQUEST DATA ‣ UNIQUE REQUEST ID ‣ USER IDENTIFIER ‣ THE MESSAGE ITSELF
  10. 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
  11. cakefest 2013 12 factor cakephp applications build better apps ‣

    reduce developer friction ‣ higher scalability ‣ increase portability ‣ decrease management overhead