際際滷

際際滷Share a Scribd company logo
Asynchronous PHP
Chris Ozog
Hi!
Im Chris
Supposedly, I love PHP. But can it really be loved?
You want to contact me? Write, and perhaps Ill write back:
/krzysztofozog
A few words about me...
A Philosopher and a Developer in one
Whats even worse is that its documented with two diplomas
Although, more of a developer:
 A creator of web apps for more than a decade now
 Created my first PHP app in 2004
 Addicted to clean code
 Technical leader at Codesushi
 A passionate CodeReviewer
The agenda of this grand meeting
1. Asynchronous PHP  is it even possible?
2. What can it be useful for?
3. A word or two about... reactPHP
4. Fine words butter no parsnips, meaning
Promises in PHP
SPOILER: Yes!
1.
Is it even
possible?
Asynchronicity in PHP?
 Asynchronous vs. multithreading vs.
forking  a revision of terms
 Asynchronicity is more of a philosophy
 than a specific mode of implementation
 What are the available options with PHP
 PThreads
 Forks (PCNTL)
Possible applications of
an asynchronous PHP
2.
What can it be
useful for?
Using an asynchronous PHP
 First of all, there is no one universal rule!
 We can use it everywhere where the app
spends much time waiting
 Websockets
 Should we start writing in an
asynchronous mode all the time now?
- No!
So the most popular option
for an Asynchronous PHP
3.
reactPHP
 Exists since 2012 (current version - 0.4.2)
 Reactor pattern (as Twisted or nodejs)
 Ratchet  websockets on react
How to avoid callback hell?!
4.
Promises in PHP
Promises
 What is a promise? - Syntactic sugar
 Two main implementations in php
 Guzzle/promises
 reactphp/promise
 Using promises:
 Simultaneous queries to api [Guzzle]
 Organizing an asynchronous code
Summary
 Asynchronous PHP  its possible!
 No sense in using it everywhere
 ReactPHP may be helpful
 Promises can also be used independently
Thank you for your attention!
Questions?
If needed, it will be easier to reach me this way:
/krzysztofozog
chris@codesushi.co

More Related Content

Asynchronous PHP | Codesushi - Warsaw 2017

  • 2. Hi! Im Chris Supposedly, I love PHP. But can it really be loved? You want to contact me? Write, and perhaps Ill write back: /krzysztofozog
  • 3. A few words about me... A Philosopher and a Developer in one Whats even worse is that its documented with two diplomas Although, more of a developer: A creator of web apps for more than a decade now Created my first PHP app in 2004 Addicted to clean code Technical leader at Codesushi A passionate CodeReviewer
  • 4. The agenda of this grand meeting 1. Asynchronous PHP is it even possible? 2. What can it be useful for? 3. A word or two about... reactPHP 4. Fine words butter no parsnips, meaning Promises in PHP
  • 5. SPOILER: Yes! 1. Is it even possible?
  • 6. Asynchronicity in PHP? Asynchronous vs. multithreading vs. forking a revision of terms Asynchronicity is more of a philosophy than a specific mode of implementation What are the available options with PHP PThreads Forks (PCNTL)
  • 7. Possible applications of an asynchronous PHP 2. What can it be useful for?
  • 8. Using an asynchronous PHP First of all, there is no one universal rule! We can use it everywhere where the app spends much time waiting Websockets Should we start writing in an asynchronous mode all the time now? - No!
  • 9. So the most popular option for an Asynchronous PHP 3. reactPHP
  • 10. Exists since 2012 (current version - 0.4.2) Reactor pattern (as Twisted or nodejs) Ratchet websockets on react
  • 11. How to avoid callback hell?! 4. Promises in PHP
  • 12. Promises What is a promise? - Syntactic sugar Two main implementations in php Guzzle/promises reactphp/promise Using promises: Simultaneous queries to api [Guzzle] Organizing an asynchronous code
  • 13. Summary Asynchronous PHP its possible! No sense in using it everywhere ReactPHP may be helpful Promises can also be used independently
  • 14. Thank you for your attention! Questions? If needed, it will be easier to reach me this way: /krzysztofozog chris@codesushi.co