Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Asynchronous tasks in PHP
Olivier Dolbeau
June 24, 2014
Programming
13
1.2k
Asynchronous tasks in PHP
Why & how making asynchronous tasks in PHP
PHPTour Lyon 2014 - 24/06/2014
Olivier Dolbeau
June 24, 2014
Tweet
Share
More Decks by Olivier Dolbeau
See All by Olivier Dolbeau
odolbeau
0
120
odolbeau
2
280
odolbeau
0
32
odolbeau
0
250
odolbeau
0
55
odolbeau
0
600
odolbeau
4
640
odolbeau
1
290
odolbeau
1
310
Other Decks in Programming
See All in Programming
malvinstn
1
650
akatsukinewgrad
0
220
nbkouhou
0
1k
s_uryu
0
210
koher
7
440
masayaaoyama
4
710
kubode
0
210
standfm
0
250
zsmb
2
110
takahi5
0
240
manfredsteyer
PRO
0
270
line_developers_tw2
0
140
Featured
See All Featured
jonyablonski
14
1.1k
jponch
103
5k
lynnandtonic
271
16k
holman
448
130k
jcasabona
7
520
keithpitt
401
20k
jnunemaker
PRO
40
4.6k
chriscoyier
499
130k
lara
590
61k
malarkey
192
8.6k
tammielis
237
23k
erikaheidi
13
4.2k
Transcript
Making asynchronous tasks in PHP
None
Olivier Dolbeau @odolbeau Web Architect About me
RIDESHARING Cost of motoring 100€ 25€ 25€ 25€ 25€ @BlaBlaCar_FR
ALONE
A fast growing community
A European phenomenon
None
None
None
None
None
Your visitors don’t want to wait! and if they have
to, they don’t want to know it
For you :
Your web servers want to make their job! (they don’t
care about emails other boring tasks)
None
Separating concerns Serveur web Consumer Consumer Consumer Consumer Consumer
Separating concerns
None
How Rabbit work?
With more consumers
You can add simple routing logic
Or more complex logic
How your app talks to RabbitMQ?
With the PECL extension Thanks to Pieter de Zwart See:
pdezwart/php-amqp Use librabbitmq (alanxz/rabbitmq-c)
How to connect to RabbitMQ?
How to publish a message?
How to consume a message?
None
None
None
None
It’s a trap !
get > consume • consume is a blocking call •
you don’t want blocking calls in your application ! • Use “get” method with a poll-interval
None
None
None
None
None
None
None
Wait 30 seconds and retry!
Wait 3 minutes and retry!
Wait half an hour and retry!
None
None
None
None
Swarrot
Existing processors
None
None
None
Last tip !
None
None
Making asynchronous tasks is good (even in PHP)
@odolbeau https://joind.in/ 11237 https://github.com/swarrot/swarrot https://speakerdeck.com/odolbeau/asynchronous-tasks-in-php