03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Real Time Chat 171<br />

PHP supports this type of programming but PHP websites have not typically been developed with<br />

this kind of model in mind. PHP developers have preferred the typical request/response model, and<br />

it’s comparatively easier than low-level socket programming.<br />

Enter ReactPHP. One of the requirements for building a fully-capable socket programming framework<br />

is creating what’s called an Event Loop. ReactPHP has this and Ratchet uses it, along with the<br />

Publish/Subscribe model to accept and maintain open socket connections.<br />

ReactPHP wraps the low-level PHP functions into a nice socket programming API and Ratchet wraps<br />

that API into another API that’s even easier to use.<br />

.<br />

You can learn more about Ratchet at: http://socketo.me/.<br />

Creating An Interface<br />

Let’s get to the code! We’re going to need an interface (kind of like a wireframe) so we know what<br />

to build with our application. Let’s set up a simple view and plug it into EmberJS.<br />

.<br />

I should mention that I am by no means an EmberJS expert. I learned all I know of it, while writing<br />

this tutorial, by following various guides. The point of this is not to teach EmberJS so much as it is<br />

to show EmberJS integration with Laravel 4.<br />

Creating A View<br />

Let’s change the default routes.php file to load a custom view:<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!