web socket with php v2

26
WebSocket with PHP

Upload: leonardo-rifeli

Post on 13-Apr-2017

156 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Web socket with php v2

WebSocket with PHP

Page 2: Web socket with php v2

Get your coffee!

Page 3: Web socket with php v2

Topics▷ What is WebSocket;▷ Browser Support;▷ About Ratchet;▷ Difficulties;▷ Examples;▷ Conclusion;▷ Questions.

Page 4: Web socket with php v2

Hello!I'm Leonardo Rifeli▷ Back-end developer at ContaAzul▷ I'm 20 years old▷ I developed more than 100

websites▷ Writer at leonardorifeli.com▷ And I'm a Java developer too

Page 5: Web socket with php v2

contaazul.com/carreiras

Work with us!

Page 6: Web socket with php v2

What is WebSocket?Definition of WebSocket

Page 7: Web socket with php v2

Definition of WebSocket

Basicamente, é uma conexão bi-direcional de um navegador web para um servidor. Depois que uma conexão socket é estabelecida a conexão permanece aberta até que o cliente ou servidor decida encerrar.

O cliente ou servidor pode enviar uma mensagem a qualquer outro cliente conectado. Uma única aplicação de servidor em execução estará ciente de todas as conexões abertas.

Page 8: Web socket with php v2

WebSocket connection example

Page 9: Web socket with php v2

HTTP connection example

Page 10: Web socket with php v2
Page 11: Web socket with php v2

NO, IS TECHNOLOGY!

Page 12: Web socket with php v2

Where to use?Ok! But, where use it?

Page 13: Web socket with php v2

ChatsYes! They are developed with socket communication.

Some Implementations

GamesThe games that use real-time update. Message by users.

Some AppsExample (Google Docs):

Page 14: Web socket with php v2

Browser SupportThey already support connection with

socket?

Page 15: Web socket with php v2

More info: https://goo.gl/0D8cf9

Yes! Except the Opera!

Page 16: Web socket with php v2

Perfect!

Page 17: Web socket with php v2

WebSocket ServerAbout Ratchet PHP WebSockets

Page 18: Web socket with php v2

About RatchetRatchet is a loosely coupled PHP library providing developers with tools to create real time, bi-directional applications between clients and servers over WebSockets. This is not your Grandfather's Internet. (socketo.me description).

Ratchet is fully PSR-0 compliant, so it naturally plays well with others. Leveraging components from Symfony2, development should feel similar to many.

Page 19: Web socket with php v2

WebSocket connection flow

Page 20: Web socket with php v2

Basic ImplementationHow to implement the Ratchet?

Page 21: Web socket with php v2
Page 22: Web socket with php v2

Implementation

▷ Ratchet\Server\IoServer: Creates an open-ended socket to listen on a specific port. Events are delegated through this to attached applications.

▷ Ratchet\Http\HttpServer: Implement the interface MessageComponentInterface and manages the connections.

▷ Ratchet\WebSocket\WsServer: The adapter to handle WebSocket requests/responses. his is a mediator between the Server and your application to handle real-time messaging through a web browser.

▷ Hermes\Business\Service\SocketService: It will be the implementation of websocket methods and contain all business rule.

Page 23: Web socket with php v2

Difficulties▷ Secutiry;▷ Latency;▷ Many connections;▷ And other points ranging from

business rule.

Page 24: Web socket with php v2

Simple Example!

Page 25: Web socket with php v2

References

▷ WebSocket no PHP: https://goo.gl/Zfysuy▷ Ratchet - PHP WebSockets:

https://goo.gl/UGX00E▷ Apresentando WebSockets: trazendo soquetes

para a web: https://goo.gl/KEZfWZ▷ More code examples: https://goo.gl/ChpAsd

Page 26: Web socket with php v2

Thanks!Any [email protected]@leonardorifeli