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

418997665c4a3368515ecf9c3d746b95?s=128

Olivier Dolbeau

April 07, 2014
Tweet

Transcript

  1. Making asynchronous tasks in PHP The easy way

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

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

  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  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
  11. Your web servers want to make their job! (they don’t

    care about emails other boring tasks) Second reason to do asynchronous
  12. None
  13. Separating concerns Serveur web Consumer Consumer Consumer Consumer Consumer

  14. None
  15. How Rabbit work?

  16. With more consumers

  17. You can add simple routing logic

  18. Or more complex logic

  19. None
  20. How your app talks to RabbitMQ?

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

    pdezwart/php-amqp Use librabbitmq (alanxz/rabbitmq-c)
  22. With videlalvaro/php-amqplib

  23. None
  24. </troll>

  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. None
  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. None
  42. None
  43. None
  44. Wait 30 seconds and retry!

  45. Wait 3 minutes and retry!

  46. Wait half an hour and retry!

  47. None
  48. None
  49. None
  50. None
  51. None
  52. None
  53. <troll>

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

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

  59. None