Live data from Hacker News

PHP in a JavaScript world

blonde.net

51–60 of 61 posts

Re: PHP in a JavaScript world

#51

I've been a PHP developer since 1997. December of 2014 I left PHP completely for NodeJS. Best decision of my life.

I'd love to play more with Node but I have free PHP hosting. I control the server completely but I have to keep PHP running. I don't how to get NodeJS to play nicely alongside bog standard LAMP stack (and all the rest of the tech) so I haven't done anything with it.

It's easy, just install Node. I mean, what complications are you having that you can't get it to work correctly?

Edit:// Also Digita Ocean $5 VPS is cheap to play with Node on, or even use a Vagrant machine.

Re: PHP in a JavaScript world

#52
My biggest problems with the article

a) He's talking about "PHP" and referring to old versions of plain vanilla PHP. He also talks about The Event Loop like it's a Node only thing: There exist such things as ReactPHP and Icicle which implement the concept. Modern PHP also comes with constructs to help with an async design

b) Node doesn't include websockets support by default either, and the comparison is made against Ratchet when it could have been made agains hoa/websocket which is both more idiomatic and nicer. As a sidenote, check them out, they make nice things.

And finally, the author marks an advantage in sharing environments when talking about languages, not runtimes. Which in and by itself is more of a curiosity.

While it could be possible to inject a PHP runtime in the frontend (and some projects like the RippleSDK somehow did), it wouldn't make sense; they don't really have the same purpose or origin, one was born in the frontend and shoehorned into the backend, and the other was born in the backend and stood there.

The way I see it, it's ultimately a matter of added value.

Why doesn't anyone actually make an Icicle vs Koa comparison? Or maybe Symfony vs ROR?

There is very little to learn from putting a toolkit (or even just the amount of tooling) against a bare language, and when people do it over and over and over it becomes clear it's just a disingenuous attempt to make the X in "PHP vs X" look good.

Re: PHP in a JavaScript world

#53
post #35

Earlier quoted context omitted.

As a server-side language, PHP has pretty much killed Perl, hasn't it?

server-side as in... shell scripts/daemons? or server-side as in... cgi/fastcgi serving to a client? because I would say 'yes' to cgi/fastcgi, but 'no' to shell scripts/daemons. There are a handful of really cool newish Perl frameworks, but unfortunately I think Perl 5's stigma is so far out there it will never gain any real traction. It seems that Perl 6 has a lot of the same stigma attached to it. I almost wish the…

I meant the cgi part.

Re: PHP in a JavaScript world

#54
post #35
post #31

Earlier quoted context omitted.

And PHP was supposed to kill Perl. At the end of the day, all of the languages being discussed here are all capable of achieving the same goals for 99% of the problems presented. Every language has its pros/cons and brings something new to the table that we usually see the others adopt.

As a server-side language, PHP has pretty much killed Perl, hasn't it?

Anecdotal: as a shared hoster engineer I would say yes. Ten years ago there were loads of Perl apps running on our shared Linux and Windows boxes, these days it's a novelty to bump into anything written in Perl.

Re: PHP in a JavaScript world

#55

Earlier quoted context omitted.

I'd love to play more with Node but I have free PHP hosting. I control the server completely but I have to keep PHP running. I don't how to get NodeJS to play nicely alongside bog standard LAMP stack (and all the rest of the tech) so I haven't done anything with it.

It's easy, just install Node. I mean, what complications are you having that you can't get it to work correctly? Edit:// Also Digita Ocean $5 VPS is cheap to play with Node on, or even use a Vagrant machine.

I'd like to have node respond to port 80 http requests for one virtual site and have Apache/PHP respond for other virtual sites so I can use the hardware I already have available. I can think of a few hacky was to make it work but it seems less than ideal.

Obviously I could pay for other hardware but I don't want to do that.

"It's easy, just install Node." funny.

Re: PHP in a JavaScript world

#56
post #26

Earlier quoted context omitted.

Very few? There's plenty of apps out there written in PHP. You can do the same thing in PHP as you can in node. Writing from scratch is no greater of a use case for using node than it is for PHP.

> There's plenty of apps out there written in PHP. Yes, there are. I didn't say there weren't. I think PHP is great, relax. In my professional experience, however, I don't see people start a codebase from scratch in PHP anymore. It's almost always based on Node.

> Very few apps are built from scratch using PHP unless the intention is to share the application code like wordpress, drupal, etc.

Err.. that's exactly what you said, no?

Well, yeah, if you work in a shop where node is the goto solution on the server side, that's going to be your experience.

Re: PHP in a JavaScript world

#57

Earlier quoted context omitted.

It's easy, just install Node. I mean, what complications are you having that you can't get it to work correctly? Edit:// Also Digita Ocean $5 VPS is cheap to play with Node on, or even use a Vagrant machine.

I'd like to have node respond to port 80 http requests for one virtual site and have Apache/PHP respond for other virtual sites so I can use the hardware I already have available. I can think of a few hacky was to make it work but it seems less than ideal. Obviously I could pay for other hardware but I don't want to do that. "It's easy, just install Node." funny.

It's a fairly common scenario. We're doing this with nginxbut docker'll be a good solution soon enough. The terms to search for are "reverse proxy".

Essentially you setup nginx to listen on port 80, Apache to listen on another port (say, 8080) and node to listen on a different port (say, 8081). Then have your nginx config differentiate between the two:

    upstream apache {
        server 127.0.0.1:8080;
    }   
    
    upstream nodeapp {
        server 127.0.0.1:8081;
    }   
    
    server {
        listen 80; 
        
        server_name myphpapp.example.com;
        
        location / { 
            proxy_pass http://apache;
            proxy_set_header Host $host;
        }   
    }   
    
    server {
        listen 80; 
        
        server_name mynodeapp.example.com;
        
        location / { 
            proxy_pass http://nodeapp;
            proxy_set_header Host $host;
        }   
    }   
IMO this gets a little easier to think about if you substitute your Apache -(mod_php)-> PHP setup for Nginx -(fastcgi)-> php-fpm - handing off to an appserver rather than a webserver.

Re: PHP in a JavaScript world

#58

Earlier quoted context omitted.

It's easy, just install Node. I mean, what complications are you having that you can't get it to work correctly? Edit:// Also Digita Ocean $5 VPS is cheap to play with Node on, or even use a Vagrant machine.

I'd like to have node respond to port 80 http requests for one virtual site and have Apache/PHP respond for other virtual sites so I can use the hardware I already have available. I can think of a few hacky was to make it work but it seems less than ideal. Obviously I could pay for other hardware but I don't want to do that. "It's easy, just install Node." funny.

Vagrant is best for setting up development environments, that way you can have as close to a production style environment as possible. Along with this you can set private IP's for each project, so 192.168.10.2 can be your LAMP stack project, and 192.168.10.3 can be your Node project.

Re: PHP in a JavaScript world

#59
post #57

Earlier quoted context omitted.

I'd like to have node respond to port 80 http requests for one virtual site and have Apache/PHP respond for other virtual sites so I can use the hardware I already have available. I can think of a few hacky was to make it work but it seems less than ideal. Obviously I could pay for other hardware but I don't want to do that. "It's easy, just install Node." funny.

It's a fairly common scenario. We're doing this with nginxbut docker'll be a good solution soon enough. The terms to search for are "reverse proxy". Essentially you setup nginx to listen on port 80, Apache to listen on another port (say, 8080) and node to listen on a different port (say, 8081). Then have your nginx config differentiate between the two: upstream apache { server 127.0.0.1:8080; } upstream nodeapp { ser…

I'm concerned about adding ngnix to the system as that's a fairly significant change to a working system. There are a lot of variables and sites involved.

I've considered reverse-proxying entirely within Apache to avoid adding ngnix another layer. But this really hinders some of the advantages of node which makes me wonder if it's worth even doing. It seems like node is best when it can handle the requests directly.

Your advice here is pretty much the most common answer.

Re: PHP in a JavaScript world

#60
post #57

Earlier quoted context omitted.

It's a fairly common scenario. We're doing this with nginxbut docker'll be a good solution soon enough. The terms to search for are "reverse proxy". Essentially you setup nginx to listen on port 80, Apache to listen on another port (say, 8080) and node to listen on a different port (say, 8081). Then have your nginx config differentiate between the two: upstream apache { server 127.0.0.1:8080; } upstream nodeapp { ser…

I'm concerned about adding ngnix to the system as that's a fairly significant change to a working system. There are a lot of variables and sites involved. I've considered reverse-proxying entirely within Apache to avoid adding ngnix another layer. But this really hinders some of the advantages of node which makes me wonder if it's worth even doing. It seems like node is best when it can handle the requests directly.…

> It seems like node is best when it can handle the requests directly

What makes you believe that?

Post reply on HN