I am in the process of developing a PHP-based Socked Driven Framework, though it's still in development stage, it is still usable to develop applications.
I have been working on this latest version for the past 3 weeks and I need to ask what features do you think are needed to make this project a real Socket Driven Framework
I want to support async development by default, even though PHP is Sync, I plan on doing this hack with NodeJS and writing the APIs in PHP
What do you think is needed ?
And for Beginner Developers, you can clone this project to learn how to create your own MVC framework. It is designed to be as slim as possible.
GITHUB REPO: https://github.com/wilforlan/CogentPHP Sample APPS: https://github.com/wilforlan/CogentBlog https://github.com/wilforlan/Automobile-Dianostic
While skimming through the hacklang docs today, I noticed Async functionality in there, maybe worth a look?
https://docs.hhvm.com/hack/async/introduction
ZeroMQ seems to have socket support in PHP as well: secure.php.net/manual/en/class.zmqsocket.php
Creating a full socket driven framework might be an interesting task since PHP scripts are typically designed to terminate after they've done their job. Not sure if HHVM would solve that.
@wilforlan this is really something that will benefit the PHP community: A good PHP/Node.js hybrid. Am excited to see the outcome :)
We had an "async PHP" discussion on Laravel #internals some weeks ago. The result of this discussion:
Even if PHP is evolving it is still not designed for async and it is better to use Node.JS for that case. Moreover, most of PHP built-in functions and libraries are sync. For example, you can't use async for PDO or file_get_contents(), however, you can use ReactPHP to improve a bit your general HTTP request-response logic and use Promises
gnugat.github.io/2016/04/13/super-speed-sf-react-…
https://www.youtube.com/watch?v=s6xrnYae1FU
And ReactPHP vs Node benchmark: https://gist.github.com/nkt/e49289321c744155484c
Don't use PHP for async, use Node.js. Use right tool for the right job.
Hmmm i would take a look at reactphp or if you want to implement it on your own you could check out https://pecl.php.net/package/libevent afaik there is another FPM like project https://github.com/PHPFastCGI/FastCGIDaemon
I would use generators as the main building blocks for the stream handling and with php 7.2 the streaming architecture of PHP gets another boost. generators will help you to keep your memory in check.
one of the questions is if you build it reactive or the classic while(true) loop + the threading system. to really scale independent you probably need a queue pipeline and maybe should be using an observer pattern to produce certain outputs.
I'm not even sure if i would go for the MVC pattern in this case, because you don't really need the controllers, but more of stateless service workers that pull the next state out of the queue and a separated state in form of session structure. the question is where to persist the state.
Since PHP usually is stateless (Request / Response) you should keep in mind what's running and how the current state of certain parts of the application are. hence the clear separation of state/structs to code logic (deterministic state machines)
I've built several such projects with distributed work systems the question is what is the main purpose ? replacing the classic PHP request response ?
It is fun to build such a thing I would first do the architecture design and separate the modules to smaller chunks by implementing an interface structure otherwise you probably will loose the oversight .... :)
@mgiambanco
Thanks alot, I really appreciate your reply.
Yes, I have, but its will take extra work to add to this project because the idea behind CogentPHP is to Optimize database Queries, and there will be event listeners that will listen for new input to database.
Though Retchet is Similar but it doesnt fit to the specification of this.
Have you looked at Ratchet for inspiration?
Co-Founder, Founder, Entrepreneur & Problem Solver
weborious
Hello! I also believe to use the right tools for each situation. So, I would suggest to use something like nodejs or golang for the "socket-required" part of your application!
Good luck my friend!