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

Asynchronous tasks in PHP

Asynchronous tasks in PHP

Why & how making asynchronous tasks in PHP
PHPTour Lyon 2014 - 24/06/2014

Olivier Dolbeau

June 24, 2014
Tweet

More Decks by Olivier Dolbeau

Other Decks in Programming

Transcript

  1. Making asynchronous
    tasks in PHP

    View Slide

  2. View Slide

  3. Olivier Dolbeau
    @odolbeau
    Web Architect
    About me

    View Slide

  4. RIDESHARING
    Cost of
    motoring
    100€
    25€
    25€
    25€
    25€
    @BlaBlaCar_FR
    ALONE

    View Slide

  5. A fast growing community

    View Slide

  6. A European phenomenon

    View Slide

  7. View Slide

  8. View Slide

  9. View Slide

  10. View Slide

  11. View Slide

  12. Your visitors don’t want to wait!
    and if they have to, they
    don’t want to know it

    View Slide

  13. For you :

    View Slide

  14. Your web servers want to make
    their job!
    (they don’t care about emails other boring tasks)

    View Slide

  15. View Slide

  16. Separating concerns
    Serveur
    web
    Consumer
    Consumer
    Consumer
    Consumer
    Consumer

    View Slide

  17. Separating concerns

    View Slide

  18. View Slide

  19. How Rabbit work?

    View Slide

  20. With more consumers

    View Slide

  21. You can add simple routing logic

    View Slide

  22. Or more complex logic

    View Slide

  23. How your app talks to RabbitMQ?

    View Slide

  24. With the PECL extension
    Thanks to Pieter de Zwart
    See: pdezwart/php-amqp
    Use librabbitmq (alanxz/rabbitmq-c)

    View Slide

  25. How to connect to RabbitMQ?

    View Slide

  26. How to publish a message?

    View Slide

  27. How to consume a message?

    View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. It’s a trap !

    View Slide

  33. get > consume
    ● consume is a blocking call
    ● you don’t want blocking calls in your
    application !
    ● Use “get” method with a poll-interval

    View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. View Slide

  38. View Slide

  39. View Slide

  40. View Slide

  41. Wait 30 seconds
    and retry!

    View Slide

  42. Wait 3 minutes
    and retry!

    View Slide

  43. Wait half an hour
    and retry!

    View Slide

  44. View Slide

  45. View Slide

  46. View Slide

  47. View Slide

  48. Swarrot

    View Slide

  49. Existing processors

    View Slide

  50. View Slide

  51. View Slide

  52. View Slide

  53. Last tip !

    View Slide

  54. View Slide

  55. View Slide

  56. Making asynchronous tasks is good
    (even in PHP)

    View Slide

  57. @odolbeau
    https://joind.in/ 11237
    https://github.com/swarrot/swarrot
    https://speakerdeck.com/odolbeau/asynchronous-tasks-in-php

    View Slide