Asynchronous tasks in PHP

Asynchronous tasks in PHP

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

418997665c4a3368515ecf9c3d746b95?s=128

Olivier Dolbeau

June 24, 2014
Tweet

Transcript

  1. Making asynchronous tasks in PHP

  2. None
  3. Olivier Dolbeau @odolbeau Web Architect About me

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

    ALONE
  5. A fast growing community

  6. A European phenomenon

  7. None
  8. None
  9. None
  10. None
  11. None
  12. Your visitors don’t want to wait! and if they have

    to, they don’t want to know it
  13. For you :

  14. Your web servers want to make their job! (they don’t

    care about emails other boring tasks)
  15. None
  16. Separating concerns Serveur web Consumer Consumer Consumer Consumer Consumer

  17. Separating concerns

  18. None
  19. How Rabbit work?

  20. With more consumers

  21. You can add simple routing logic

  22. Or more complex logic

  23. How your app talks to RabbitMQ?

  24. With the PECL extension Thanks to Pieter de Zwart See:

    pdezwart/php-amqp Use librabbitmq (alanxz/rabbitmq-c)
  25. How to connect to RabbitMQ?

  26. How to publish a message?

  27. How to consume a message?

  28. None
  29. None
  30. None
  31. None
  32. It’s a trap !

  33. get > consume • consume is a blocking call •

    you don’t want blocking calls in your application ! • Use “get” method with a poll-interval
  34. None
  35. None
  36. None
  37. None
  38. None
  39. None
  40. None
  41. Wait 30 seconds and retry!

  42. Wait 3 minutes and retry!

  43. Wait half an hour and retry!

  44. None
  45. None
  46. None
  47. None
  48. Swarrot

  49. Existing processors

  50. None
  51. None
  52. None
  53. Last tip !

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

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