Promises in PHP

Posted by Unknown on Monday, June 23, 2014

We just released sabre/event 2.0 last week, featuring support for Promises.


It's still kinda rare to need Promises in PHP. PHP isn't asynchronous the same way languages such as javascript are, and there's no real eventloop, unless you're one of the few that use libevent in PHP. It actually too me a long time to fully grasp promises up to a point where I was comfortable writing an implementation.


So dispite being interested in the pattern, it took a while for me to find a use-case where it actually made sense to deploy it.


Recently I was tasked to write a client for a webservice that would require:



  1. Lots and lots of HTTP request for many users.

  2. Some of which were required to happen in a specific order.

  3. Others could happen in paralel.


Using Promises was absolutely ideal here, and a lot of fun. So I added it to the sabre/event library.


I managed to compress the full concept into a single, relatively class, but it took a fair bit of step-through debugging to figure out what I did wrong at times.


The full documentation for it can be found on the website.




more

{ 0 comments... » Promises in PHP read them below or add one }

Post a Comment

Popular Posts