Symfony Nano Framework, a cunning plan

Symfony Nano Framework, a cunning plan

All frameworks seem to have their own micro framework: Zend framework has Expressive, Laravel has Lumen. But what does Symfony have? Silex? MicroKernelTrait? Hah! The stuff's as boring as a pacifist pistol. But don't worry, for I have a plan as cunning as a fox who's just been appointed Professor of Cunning at Oxford University.

A78c676a05cd6d653609b237ed515601?s=128

Loïc Faugeron

May 15, 2017
Tweet

Transcript

  1. Symfony Nano Framework It’s so minute it wouldn’t be able

    to cover a small water biscuit Loïc Faugeron http://constant.co @epiloic
  2. Loïc Faugeron gnugat @epiloic Blog - https://gnugat.github.io 2

  3. Constant Commerce Symfony 3, PHP 7, phpspec @epiloic Site -

    http://constant.co 3
  4. Symfony Nano Framework Micro @epiloic 4

  5. 1. Micro Framework? 2. Standard Edition 3. Symfony Flex 4.

    Empty Edition 5. Micro Framework Bundle
  6. 1. Micro Framework? What does it mean for you?

  7. @epiloic 7 Examples • Laravel: Lumen • Zend: Expressive •

    Symfony: ???
  8. @epiloic 8 Silex? Bundles Incompatibility

  9. @epiloic 9 MicroKernelTrait? Fabpot: It’s just a regular Kernel with

    some method helpers [...] There’s nothing micro here See Fabien’s comments - https://github.com/symfony/symfony/pull/15990#r40645358
  10. @epiloic 10 Symfony?

  11. @epiloic 11 • HttpKernel • Routing • DependencyInjection • EventDispatcher

    • Config
  12. @epiloic 12 Hello World

  13. @epiloic 13 Metrics

  14. @epiloic 14 API (usage in your app) Number of steps

    to add new route
  15. @epiloic 15 Dependencies composer show | wc -l

  16. @epiloic 16 Footprint Apache Benchmark and Blackadder Blackfire

  17. 2. Standard Edition Solves 80%, out of the box

  18. @epiloic 18 composer create-project symfony/framework-standard-edition cd framework-standard-edition

  19. @epiloic 19 <?php // src/AppBundle/Controller/DefaultController.php namespace AppBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use

    Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class DefaultController extends Controller { /** * @Route("/", name="homepage") */ public function indexAction(Request $request) { return new Response('Hello World'); } }
  20. @epiloic 20 SYMFONY_ENV=prod composer update -oa --no-dev php -S localhost:2502

    -t web & curl 'http://localhost:2502/app.php' ab -c 10 -t 10 'http://localhost:2502/app.php' killall php
  21. @epiloic 21 Results • API: 1 step to add new

    route • Dependencies: 85 (34 + 51) • Footprint: 400 req / s
  22. @epiloic 22

  23. 3. Symfony Flex Add what you need

  24. @epiloic 24 composer create-project symfony/skeleton:3.3.x-dev cd skeleton composer require symfony/dotenv

  25. @epiloic 25 # .env ###> symfony/framework-bundle ### APP_ENV=prod APP_DEBUG=0 APP_SECRET=31611929636ceb325e27091c2856ab8b

    ###< symfony/framework-bundle ###
  26. @epiloic 26 <?php // src/Controller/HelloController.php namespace App\Controller; use Symfony\Component\HttpFoundation\Request; use

    Symfony\Component\HttpFoundation\Response; class HelloController { public function world(Request $request) { return new Response('Hello World'); } }
  27. @epiloic 27 # etc/routing.yaml hello_world: path: / defaults: _controller: ‘App\Controller\HelloController:world’

    methods: - GET
  28. @epiloic 28 composer update -oa --no-dev php -S localhost:2504 -t

    web & curl 'http://localhost:2504/index.php' ab -c 10 -t 10 'http://localhost:2504/index.php' killall php
  29. @epiloic 29 Results • API: 2 steps to add new

    route [+1] • Dependencies: 28 [/3] • Footprint: 950 req / s [x2.5]
  30. @epiloic 30

  31. @epiloic 31

  32. 4. Empty Edition Add what you need

  33. @epiloic 33 composer create-project gnugat/symfony-empty-edition cd symfony-empty-edition

  34. @epiloic 34 <?php // src/AppBundle/Controller/HelloController.php namespace AppBundle\Controller; use Symfony\Component\HttpFoundation\Request; use

    Symfony\Component\HttpFoundation\Response; class HelloController { public function world(Request $request) { return new Response('Hello World'); } }
  35. @epiloic 35 # app/config/services/controller.yml services: app.hello_controller: class: ‘AppBundle\Controller\HelloController’

  36. @epiloic 36 # app/config/routings/app.yml hello_world: path: / defaults: _controller: app.hello_controller:world

    methods: - GET
  37. @epiloic 37 SYMFONY_ENV=prod composer update -oa --no-dev php -S localhost:2503

    -t web & curl 'http://localhost:2503/app.php' ab -c 10 -t 10 'http://localhost:2503/app.php' killall php
  38. @epiloic 38 Results • API: 3 steps to add new

    route [+1] • Dependencies: 25 [/1.1] • Footprint: 1 000 req / s [x1.1]
  39. @epiloic 39

  40. @epiloic 40

  41. 5. MicroFrameworkBundle Add what you need++

  42. @epiloic 42 composer require gnugat/micro-framework-bundle composer remove symfony/framework-bundle

  43. @epiloic 43 <?php // app/AppKernel.php use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; class

    AppKernel extends Kernel { public function registerBundles() { return array( new Gnugat\MicroFrameworkBundle\GnugatMicroFrameworkBundle(), new AppBundle\AppBundle(), ); } // ... }
  44. @epiloic 44 # app/config/config.yml imports: - { resource: parameters.yml }

    - { resource: services/ }
  45. @epiloic 45 rm -rf var/* SYMFONY_ENV=prod composer update -o --no-dev

    php -S localhost:2505 -t web & curl 'http://localhost:2505/app.php' ab -c 10 -t 10 'http://localhost:2505/app.php' killall php
  46. @epiloic 46

  47. @epiloic 47 Results • API: 3 steps to add new

    route [0] • Dependencies: 16 [/1.5] • Footprint: 1 200 req / s [x1.2]
  48. Conclusion

  49. @epiloic 49 Questions?

  50. @epiloic 50 Resources Blackadder II Blackadder the Third Blackadder goes

    forth http://gnugat.github.io/micro-framework-bundle/