$30 off During Our Annual Pro Sale. View Details »

Making asynchronous tasks in PHP

Making asynchronous tasks in PHP

Why & how making asynchronous tasks in PHP
SFLIve2014 - 04/07/2014 with Grégoire Pineau

Olivier Dolbeau

April 07, 2014
Tweet

More Decks by Olivier Dolbeau

Other Decks in Programming

Transcript

  1. Making asynchronous
    tasks in PHP
    The easy way

    View Slide

  2. Olivier Dolbeau
    Dev
    @odolbeau
    Who ?
    Grégoire Pineau
    Dev
    @lyrixx

    View Slide

  3. Summary
    ● Why?
    ● How?
    ● Problems? Solutions!
    ● Tips

    View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. View Slide

  10. Your visitors don’t want to wait!
    (and if they have to, they don’t want to know it)
    First reason to do asynchronous

    View Slide

  11. Your web servers want to make
    their job!
    (they don’t care about emails other boring tasks)
    Second reason to do asynchronous

    View Slide

  12. View Slide

  13. Separating concerns
    Serveur
    web
    Consumer
    Consumer
    Consumer
    Consumer
    Consumer

    View Slide

  14. View Slide

  15. How Rabbit work?

    View Slide

  16. With more consumers

    View Slide

  17. You can add simple routing logic

    View Slide

  18. Or more complex logic

    View Slide

  19. View Slide

  20. How your app talks to RabbitMQ?

    View Slide

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

    View Slide

  22. With videlalvaro/php-amqplib

    View Slide

  23. View Slide


  24. 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. 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. View Slide

  42. View Slide

  43. View Slide

  44. Wait 30 seconds
    and retry!

    View Slide

  45. Wait 3 minutes
    and retry!

    View Slide

  46. Wait half an hour
    and retry!

    View Slide

  47. View Slide

  48. View Slide

  49. View Slide

  50. View Slide

  51. View Slide

  52. View Slide


  53. View Slide

  54. View Slide

  55. View Slide

  56. View Slide

  57. You can take a look at the code !
    https://github.com/odolbeau/sflive2014-workers

    View Slide

  58. Swarrot
    https://github.com/swarrot/swarrot

    View Slide

  59. View Slide