Server sent events and phalcon

Hello!

I have a question about using SSE (Server Sent Events) with Phalcon framework.

  1. As we know, in most cases, for use SSE we need to start "Event loop" using server with such ability (Node.js, for example).
  2. My system are deployed with apache and nginx (with php and Phalcon).

Question is: How to use Phalcon abilities and SSE technology?



83.0k

Phalcon is a web framework for PHP while node.js is a network framework. You can create an event loop in PHP using any of these extensions:

http://php.net/manual/en/intro.ev.php http://www.php.net/manual/en/book.libevent.php

However you need to simulate the request/response environment for each incoming connection. Note that PHP wasn't designed to work efficiently in these environments.



24.8k

Thank you for the reply!

Yes, I can create an event loop in PHP with libev, but some folks talk that it will be much slower than event loop in Node.js (or something else), because PHP was designed to work in the request-response paradigm, and so on...

So I decided to create an event loop in Node.js to request data from "Phalcon-servers" (php+apache/nginx) with request.js library (https://github.com/mikeal/request) .

So, the question is: How do you think what is preferable*: 1. PHP+Phalcon+libev 2. PHP+libev+curl->Phalcon 3. Node.js+request.js->Phalcon?

*preferable, for me, means faster and scalable :)



83.0k

Both PHP and Node.js are faster and scalable. I wouldn't use PHP for event loops, using the wrong tool for the job always lead to disappointments.

Node.js+request.js -> PHP/Phalcon can be a good option, however the http request can become soon or later a bottleneck in your architecture. I would try to use only node if PHP is not doing something that node.js can't.



24.8k

Thank you!

I'll try to use "clean" node.js, but it will be more-more complicated for maintaining. It seems that main feature in PHP/Phalcon that we will need to realize in node.js is user access control...