Slide 1

Slide 1 text

is Phun!

Slide 2

Slide 2 text

What is an Unconference? unconference ˈʌnkɒnf(ə)r(ə)ns/ noun noun: unconference; plural noun: unconferences 1. a loosely structured conference emphasizing the informal exchange of information and ideas between participants, rather than following a conventionally structured programme of events. 2. "at this unconference, attendees created sessions on the spot, making for an energizing and freewheeling exchange"

Slide 3

Slide 3 text

What did we conf about? ● Testing ○ TDD/BDD ● UI/UX/Frontend ○ AngularJS ○ UX ○ Grunt/Gulp ● Frameworks ○ Symphony 2.0 ○ Zend Fw 3.0 ○ Laravel ● API/SOA ● PHP Runtime ○ HHVM ○ PHP7 ● Data Storage ○ MongoDB

Slide 4

Slide 4 text

Workshops ● PHP History ● Zend Masterclass ● Aspect Oriented Programming ● PHP at Scale ● PHP Security ● TDD Code retreat

Slide 5

Slide 5 text

Before there was PHP... ● (1962) J.C.R. Licklider of MIT poses the ‘Galactic Network’ concept (DARPA) ● (1967) ARPANET plan published ● (1974) ‘Internet’ term RFC675 (TCP) ● (1976) X.25 TTY/ BBSes ● (1981) ARPANET expanded to CSNET ● (1989) Tim Berners-Lee invents www. ● (1989) AARNET (and various regionals) ● (1992) NSFNET Interconnect approved ● (1995) Commercial traffic restrictions over the NSFNET end, and so begins the age of the internet http://www.internetsociety.org/internet/what-internet/history-internet/brief-history-internet

Slide 6

Slide 6 text

PHP is born ● (1995) 1.0 - "Personal Home Page Tools" || PHP Tools ○ Written in C, interacted via CGI, 17mo to write ○ HTML + DBs + Web Form libraries for his résumé site ○ (HTML Comments) ○ Shared code on USENET to fix bugs / write better code ○ “It doesn’t make sense writing large apps in PHP” ○ “There are people who actually like programming. I don't understand why they like programming.” ○ “I don't know how to stop it, there was never any intent to write a programming language” ● (1997) PHP 2.0 "PHP/Forms Interpreter" || PHP/FI 2.0 ○ +Zeev Suraski +Andi Gutmans ○ Some people really liked it dev team grow-oh-oh’ed ○ Used really_long_variable_or_function_etc_names to evenly distribute ‘things’ in memory http://en.wikiquote.org/wiki/Rasmus_Lerdorf Rasmus Lerdorf - First developer of PHP

Slide 7

Slide 7 text

PHP in it’s infancy ● (1998) 3.0 - PHP: Hypertext Preprocessor (recursive names were a thing) ○ 60,000 Domains ~1% of the internet (May 1998 Netcraft Survey) ○ Rewrite of internal parser ○ Many more developers joining core team ○ Peaked at ~10% of the interwebs ● (2000) 4.0+ Zend Engine ○ Better performance, Sessions, Security, Basic OOP ○ PEAR (PHP Extension and Application Repository) ○ PHP Quality Assurance Initiative ○ $_GET, $_POST, $_SESSION superglobals in 4.1 ○ CLI in 4.3 https://line.do/history-of-php/r5q4x1/vertical https://line.do/php-evolution/8oq/vertical

Slide 8

Slide 8 text

PHP - The Wonder Years ● (2004) 5.0-5.1 Zend Engine 2 ○ Now dozens of developers + dozens more on libs ○ Re-engineered cores, massive perf. improvements, PDO, Native JSON support ○ 10M - 100M installs…. > ENTIRE INTERNET 1998 ● (2009) 5.3 <-GAF (Unsupported from Jun 2014) ○ Namespace support, Native closures, Garbage collection of circular references ○ PHAR, Internationalization extension ○ 2010 HipHop released, HHVM / Hack developed ○ > 140 bugs fixed ● (2010-11) PHP-FPM, PHP-FIG, Composer, MOAR frameworks ○ FastCGI Process Manager much faster for websites at scale ○ PSR code standards developed ○ Composer developed for dependency management http://www.php-fig.org/

Slide 9

Slide 9 text

PHP - Adulthood ● (2012) 5.4 (Security fixes->June ‘15) ○ Performance improvements, less memory usage ○ Removed some legacy functions ● (2013) 5.5 (Supported till June ‘16) ○ Zend Optimizer+, OpCache default ○ Generators (more memory efficient iteration) ● (2014) 6.0 -> 5.6 (Supported till June ‘17) ○ POST data memory usage reduced 2-3x ○ Importing namespaced functions /constants ● (2015) PHP7 ○ PHP7-RC -> Jun 2015 ○ HHVM/Hack Mature ○ Both strongly typed!!! :D ○ First PHP Australia conference http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design

Slide 10

Slide 10 text

PHP7 (php-ng) ● Feature freeze -> RC -> June 2015 ● MUCH faster at the core engine level ● True 64bit support ● Large string / LFS ● Supports strong typing ● EngineException (Fatals, non-object refs) ● ?? null-coalesce operator ● Deprecate PHP4 eregs ● Unicode escaping, true Internationalization ● Lower memory consumption ● php-ng execution (CPU) outperfoms HHVM in many cases… in spite of no JIT! http://zsuraski.blogspot.com.au/2014/07/benchmarking-phpng.html https://github.com/php/php-langspec

Slide 11

Slide 11 text

PHP Under the hood ● Interpreted, compiled to tokens & OpCodes ● Major bottlenecks often due to DB / MemCache / Redis / Thrift / API ● PHP is rarely the bottleneck ● VLD - Vulcan Logic Disassembler https://speakerdeck.com/dshafik/phpnw14-php-under-the-hood http://pecl.php.net/package/vld

Slide 12

Slide 12 text

HHVM / Runtime opt. ● Used by many large webapps ● Supports many PHP libs/fws ○ phpunit, phpunit-mock-objects ○ composer, symfony, ZF etc. ● Bug-for-bug compatible with PHP~5.6 ● Just-in-time (JIT) compilation ○ 2x interpreted PHP speed ○ Multiple versions of your code ○ Repo Authoritative mode +25% ○ Drop in replacement for PHP-FPM ○ Performance hit on each sync till spool-up ● Hacklang ○ + type hinting, async functions ○ - prevents HTML in PHP, globals etc. ○ Hackification (@types, log, harden) ● LTS +1 year after release, 6mo cutover http://ma.ttias.be/hhvm-versus-php-fpm-5-4-and-5-5-performance-comparison/ http://www.slideshare.net/pierrej

Slide 13

Slide 13 text

Test Driven Development ● Write tests first that fail, and then make them pass by implementing ● A testing mindset forces you to think about the architecture of your system more ○ Forces you to think about implementation and plan before you write

Slide 14

Slide 14 text

TDD Workshop ● Write Conway’s game of life with TDD ● Pair programming ● Start from scratch every 45 mins

Slide 15

Slide 15 text

What we learned from the workshop ● Planning for testing ○ Decoupling implementation code - i.e. separate rules in Conway’s GOL ● Cover requirements from spec instead of chasing coverage ● Keep tests as specific as possible

Slide 16

Slide 16 text

Improving testing ● Test readability is important when debugging ● Tests need to be maintained too, or they become useless and you can’t trust them ● Use helper functions to improve readability http://www.agitar.com/downloads/TheWayOfTestivus.pdf

Slide 17

Slide 17 text

TDD Ping Pong ● Get two programmers ● One writes the tests ● The other reads the tests and starts implementing them ● No talking! Communicate via tests ● The only way you control implementation is through tests ● Experiment you can run in your own teams

Slide 18

Slide 18 text

TDD Ping Pong ● Carried out an experiment with Memberships team. ● Wrote a really simple test for DAO (Python service) and then one of us had to implement this. Watch them implement! ● Changes how you write tests when you see someone trying to implement straight from your tests.

Slide 19

Slide 19 text

TDD Ping Pong ● When tests fail people look straight for the assert statements. Make meaningful assert statements. Comments help out a lot. assertTrue(log.status == 1) assertEquals( log.status, SubscriptionStatus.SUBSCRIBED.value )

Slide 20

Slide 20 text

Code Coverage “In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite.” “If I can’t test it, I don’t trust it” “How many tests are enough?”... “100% test coverage is a really good start”

Slide 21

Slide 21 text

OMG LOOK 100% TEST COVERAGE function whatsNext($num1,$num2) { $out = ''; for ($i = 0; $i < $num1, $i++) { if ($num2 > $num1) { $out .= $num1 . ' then ' . $num2; } } return $out; } function testWhatsNext('test'){ $this->assertEquals(whatsNext(2,1),'1 then 2'); }

Slide 22

Slide 22 text

Lies, Damned Lies and Code Coverage function whatsNext($num1,$num2) { $out = ''; for ($i = 0; $i < $num1, $i++) { if ($num2 > $num1) { $out .= $num1 . ' then ' . $num2; } } return $out; } function testWhatsNext('test'){ $this->assertEquals(whatsNext(2,1),'1 then 2'); } “Code Coverage is a measure of how many lines of code a unit test suite has executed. Not tested. Executed” http://blog.astrumfutura.com/2015/01/lies-damned-lies-and-code-coverage-towards-mutation-testing/

Slide 23

Slide 23 text

Lies, Damned Lies and Code Coverage “Let’s imagine that you have 100% Code Coverage. That’s actually a lie. More specifically, you actually have 100% Line Coverage. PHP_CodeCoverage and XDebug are incapable, at this time, of measuring Statement Coverage, Branch Coverage, and Condition Coverage. Your 100% score is only 25% of the story. Let’s call it 10% because I’m mean and there are other forms of Coverage that I have not mentioned.” ● phpunit code coverage inaccurate ● Do your tests -really- cover all cases? ● How can you be sure? http://blog.astrumfutura.com/2015/01/lies-damned-lies-and-code-coverage-towards-mutation-testing/

Slide 24

Slide 24 text

Test your tests with Humbug ● Mutation testing ○ Injects small defects into code ■ > to < ■ != to == ■ (;i<10;i++) to (;i < 10;i--) ■ if / else / while etc. ○ Supports phpunit ○ Fault tolerant (∞ loops, fatals etc.) ● Requires a complete set of test cases (not tests) ● Gives a level of assurance that the system won’t break in unforeseen situations (test coverage does not) https://github.com/padraic/humbug

Slide 25

Slide 25 text

Other PHP Australia Highlights ● The Rasmus on PHP ● Monty on MariaDB vs MySQL ● Holistic performance improvement… anything > 100ms is too slow! ● QB / Zephir, moar runtime optimisation ● Process @Github ● Scaling delivery tracking @ Etsy ● REST done right ● Grunt php-unit ● Composing Composer ● How to make a PHP virus/worm in 15mins http://www.phpconference.com.au/#speakers