top | item 3995574

React is a PHP port of NodeJs non-blocking I/O platform

124 points| romainneutron | 14 years ago |nodephp.org

111 comments

order
[+] Edootjuh|14 years ago|reply
Let me make sure I understand...

Is this meant to be run on a web hosting service that supports PHP in the 'traditional' way or do you need permission to run this as a daemon?

If it's the former, I can definitely see its benefits, but if it's the latter I can only imagine the target audience being people who refuse to program in anything but PHP and people who are by some bizarre policy required to use PHP but are allowed to run their own HTTP server.

[+] encoderer|14 years ago|reply
Let me preface this with a full disclosure: I've also waded into the depths of many of the PHP APIs that the OP has used to produce this project. I've created a general-purpose PHP daemon library (http://shaneharter.github.com/PHP-Daemon/).

There is no question that the PHP implementation of these APIs (think: Socket, SystemV, POSIX, etc) is very underwhelming compared to something you'd get in Python, Java, or nearly any language. And it's partly because of that that I felt it would be irresponsible for me not to include a disclaimer at the top of my github readme:

For many reasons PHP is not an optimal language choice for creating servers or daemons. I created this library so if you must use PHP for these things, you can do it with ease and produce great results. But if you have the choice, Java, Python, Ruby, etc, are all better suited for this.

So that being said:

With a general-purpose daemon library, there's a 3rd use-case to what you described: People who need to create daemons/servers/etc that use a large existing codebase: maybe it needs to share the 80 models that run your primary website. Maybe you've written a large domain-specific library. That sort of thing.

While it's a little more difficult for me to apply those reasons to a Tornado port, I'd like to hear from the developers first before I dismissed their work.

[+] vog|14 years ago|reply
I fully agree that for a new project, you shouldn't use PHP for any other reason than the ubiquitous hosting.

However, for existing projects and/or existing teams there might be another reason to stick with PHP: As a common denominator across all team members.

[+] FuzzyDunlop|14 years ago|reply
I'm interested as to how you'd run it as a server without PHP 5.4. Looking at the code, it's written to be compatible with PHP >= 5.3.2, and the composer.json doesn't specify 5.4 as the minimum version.

It also wraps Silex and includes Guzzle (some sort of API consuming thing). Trying to gain credibility from using Node's name seems a little disingenuous given that it's microframework with an event loop of some sort plugged in, and an analogous 'hello world'.

[+] kamaal|14 years ago|reply
>>I can only imagine the target audience being people who refuse to program in anything but PHP

Such people exist in every language community. You name the famous language and there you will fine people wanting to do everything in that language. This is nothing to specific to php.

There are various reasons for that, Once a person learns a language it becomes an investment- In time and other things and, as time grows out a person begins to think in that language, its paradigms, its idiomatic way of working. He may learn more than one language. But he will bear allegiance to one specific language.

[+] michh|14 years ago|reply
How is PHP's garbage collection for these kinds of things? Usually, it doesn't need to be that good as you can just release all the memory after a request is processed in the typical way PHP is used.

Anyone have experience running PHP-based daemons or things like that? If your React/NodePHP-application crashes on a 'Allowed memory size exhausted' every two days, it'll get old quick.

[+] rmccue|14 years ago|reply
5.3 and 5.4 are a lot better, but I can't say I'd use them for long running daemons. Personally, I usually use Python daemons that spin up a PHP instance if they need.
[+] dewiz|14 years ago|reply
I created a server-less distributed network composed by PHP daemons some years ago, it was really fun seeing them linking, automatically discovering new nodes and distributing a task among the available nodes.

We chose PHP because it was the only technology supported in the company, who didn't want to invest on consultancy, research, just do it now, you know.

It was fun, but eventually PHP bad memory management became the main issue, so we were restarting daemons that would crash at random times, often in the middle of some tasks, other times while idle.

Today, I would never create a new project like that using PHP, it doesn't make sense. PHP is great for templating, scripting, and there are some nice frameworks for the classic web applications. However each language has some limitations, an engineer should know much better than that.

[+] lux|14 years ago|reply
At least having more scripts like this could be helpful in improving PHP's memory management.
[+] hinathan|14 years ago|reply
I built the same basic thing a year ago (using libevent for php, same general API as node.js) for a particular project.

https://github.com/hinathan/edges-php#summary

For some these php-but-like-node.js projects are abominations but there are a few reasonable use cases.

Of course the vast majority of php and the php 'class library' isn't appropriate for this programming model but neither was most of the existing js corpus before people built an ecosystem around node.js.

[+] IsaacSchlueter|14 years ago|reply
Actually, a surprising amount of JS code was already built around event-driven IO. It took a remarkably small amount of work to get YUI3 running on node, for example.
[+] flashmob|14 years ago|reply
It should not be surprising that this can be done in php.

The libevent extension for event driven non-blocking I/O has been added some time ago. Together with many nice new features since PHP 5.3, including improved garbage collection and speed improvements, it naturally follows that php will be used for these things.

Btw, the libevent extension is really fantastic. If you're doing server programming, take a look at it, it will turbo-charge your server http://php.net/manual/en/book.libevent.php

Perhaps php lost some if its sexiness, but it's still rapidly evolving and improving.

[+] FuzzyDunlop|14 years ago|reply
So is it called React, or Node.PHP? It seems a little confused with its own identity.
[+] IsaacSchlueter|14 years ago|reply
Indeed. It almost seems like Node.js is somehow involved with this project.

(It isn't.)

[+] triathlete|14 years ago|reply
To say this is a port of Node is to misunderstand 99% of what node is. In fact i dont really understand why you even relate this to node at all and why you use the node logo. Call it evented php or or a port of Tornado or something but its not node. If you want to learn what node is listen to Nodeup. Its an awesome podcast with core node people in it that talk about what node is and why it is what it is and why javascript is so integral to it.
[+] Kiro|14 years ago|reply
I'm proud to say PHP is my main language and this looks great.
[+] DanWaterworth|14 years ago|reply
This is a little off topic, but can I ask, have you used any other languages in any significant way and if so what keeps you coming back to PHP?
[+] rheide|14 years ago|reply
Target audience mismatch.
[+] nodesocket|14 years ago|reply
Interested in seeing a benchmark between React vs native node hello world.
[+] lstoll|14 years ago|reply
I'd rather see a benchmark of a more real-world case. These hello world microbenchmarks don't show anything.
[+] usamec|14 years ago|reply
this is a joke, right?
[+] fsniper|14 years ago|reply
I think it's not a joke. look at the source code on github.

But I can't understand this elitism. Programming language choice must not be a cult. Anyone should be free whatever language they like to use whatever they want to do.

So bringing something good or seemingly good to any ecosystem should not get bad responses. They are trying to combine two worlds into a "new choice". Let them do even if yo do not like it. Nobody asks you to praise but just don't give uninformative bad responses.

[+] obiterdictum|14 years ago|reply
Judging by the "React in the Industry" section, this was my thought too. In fact, I was sure it is until I saw serious comments here.
[+] paulbjensen|14 years ago|reply
I think so, seeing how they ripped off the nodejs.org site.
[+] adeelk|14 years ago|reply
Simple deployment is the only advantage people usually cite of PHP, and this seems to eliminate that. So, why?
[+] Joeboy|14 years ago|reply
Availability of coders is another advantage. Not necessarily particularly great coders, but they have the numbers.
[+] mmaunder|14 years ago|reply
This is awesome, congrats! Long polling coming soon to pure PHP with 10,000 times less memory consumption.
[+] Kudos|14 years ago|reply
Long-polling of what? Connecting to any datasource is going to block the event loop.
[+] tdot|14 years ago|reply
PHP doesn't have closure like JavaScript. JS accomplished language for evented approach. Because JS have got closure, cascaded scope and prototype chaing.
[+] notJim|14 years ago|reply
PHP has had closures for 3 years.
[+] smagch|14 years ago|reply
Luvit, Vert.x and React! A lots of projects from NodeJs. This tells how revolutionary NodeJS is. I bet React is the slowest one.
[+] eropple|14 years ago|reply
Hate to burst your bubble, but "how revolutionary node.js is" has very little to do with anything. For example, Vert.x is a formalization (albeit a good one) of Netty-based practices we've been using for years in the Java ecosystem--I've got a "Vert.x prototype" in my projects graveyard and it's been there for years. Pretty much the same idea, though with a lot less love poured into it.

Don't get me wrong, I like Vert.x's API quite a lot and it's why I'm looking at using it. But it's not really "new", it just has a nicer coat of paint. And claiming that node.js is "revolutionary" because of it is a fairly criminal disservice to the ridiculously smart people behind Netty, Mina, and similar projects that have been around for a long time.

[+] benschwarz|14 years ago|reply
I want to say this library is the best troll ever. Then I see all the real code on Github.
[+] Zash|14 years ago|reply
Dear lord, what will they come up with next? PHP as browser scripting language?
[+] gcb|14 years ago|reply
I'd see more value in a non blocking Apache.