Live data from Hacker News

PHP 7 Virtual Machine

nikic.github.io

21–30 of 128 posts

Re: PHP 7 Virtual Machine

#21
post #15

Earlier quoted context omitted.

out of pure ignorance -- what are the correct domains that either fit into?

nodejs is imho best suited for two groups of tasks: 1) APIs/programs relying on high concurrency and parallelism, especially where the handler(s) have to wait a lot for stuff like DB accesses 2) streaming (in the sense of websockets servers), PHP iirc can't even be used as a websocket server 3) Any API that can be implemented without needing too many async calls - you'll end up in callback hell or promise hell otherw…

> PHP iirc can't even be used as a websocket server

True, if you run it behind a web server like 99.999% of all users.

If you run it as a cli script, you can implement pretty much anything. I saw a ftp server once. Crazy.

Still, even on a normal web server, php can do long polling perfectly fine, which is often enough.

> being able to write program flows without dozens of promises is a breeze

It is a breeze with async/await too.

Re: PHP 7 Virtual Machine

#22
post #15
post #13

Earlier quoted context omitted.

I wholeheartedly agree. I've seen many cases of PHP being scorned in favour of Node.js in problem domains where PHP is a clear fit (I've been guilty of this myself). It's not at all a bad language in the hands the right person.

out of pure ignorance -- what are the correct domains that either fit into?

PHP started out as a language you could embed into otherwise static HTML via SGML processing instructions. While useful, the problem was (and still is) that embedded PHP templating operates at the string level and has absolutely no concept of HTML-awareness so can't escape the strings it injects into HTML - it's trivially easy to build a PHP app taking user input where the user sends malicious tags and PHP placing it happily into generated HTML (eg. XSS attacks). PHP apps typically also build up dynamic SQL from user input by string concatenation, which has resulted in uncountable SQL injection attacks. PHP apps and frameworks like WordPress and Drupal initially have worked around these limitations by using ad-hoc measures, then grew into meta site template engines and generators themselves, resulting in code bases without much architectural oversight. These dangerous properties, and PHP's really bad standard library, in combination with PHP being used as a beginner language for web sites, have resulted in PHP's bad reputation. Since experienced developers have avoided it, PHP also has a bad presence at StackOverflow, which contains thousands of low quality answers answers to PHP questions.

On the plus side, PHP really owns managed hosting. You can install WP etc. via "panels" even without any admin experience and go from there by installing a mess of "plugins" and "themes" (which, due to lack of modularity, can do all kind of things to your site).

Node.js generally requires your own VM (there is no managed hosting) and due to it being run in a single process (or process cluster) generally requires that you know what you're doing so that a single error doesn't bring down your whole site. Its attractiveness comes from the fact that you can use JavaScript both server- and client-side (unlike PHP which runs server-side only). While Node.js has the edge in web apps, the options for content-driven sites are limited on Node.js; there's nothing like WP or Drupal for Node.js, and some say Node.js also lacks a canonical framework for rapid creation of database-driven web apps such as Rails or Django.

Re: PHP 7 Virtual Machine

#23
post #15

Earlier quoted context omitted.

out of pure ignorance -- what are the correct domains that either fit into?

nodejs is imho best suited for two groups of tasks: 1) APIs/programs relying on high concurrency and parallelism, especially where the handler(s) have to wait a lot for stuff like DB accesses 2) streaming (in the sense of websockets servers), PHP iirc can't even be used as a websocket server 3) Any API that can be implemented without needing too many async calls - you'll end up in callback hell or promise hell otherw…

With regards to 2, I have experienced this. As a solution, I built a websocket server using NodeJS. I then built an API in express that PHP / Gulp used to push messages to be sent via websocket.

There might be a better way but I'd effectively added support for server push from our PHP app in a morning, with great results.

The other thing it provided me was clear evidence of the "best tool for the job" in a shop that demanded PHP.

The problem I have with PHP is what is usually touted as it's benefit. It's easy to find PHP developers. The problem: most of them are not very good.

To close, there are many more PHP RFCs that internals should approve, e.g arrow lambdas with automatic variable closure, design by contract, etc. These could really bring the language into it's own.

Re: PHP 7 Virtual Machine

#24
post #15

Earlier quoted context omitted.

out of pure ignorance -- what are the correct domains that either fit into?

nodejs is imho best suited for two groups of tasks: 1) APIs/programs relying on high concurrency and parallelism, especially where the handler(s) have to wait a lot for stuff like DB accesses 2) streaming (in the sense of websockets servers), PHP iirc can't even be used as a websocket server 3) Any API that can be implemented without needing too many async calls - you'll end up in callback hell or promise hell otherw…

There is a project called ReactPHP [1] which provides a nodejs-like event loop and async execution.

However, I think the power of PHP is that it is not designed to be its own server, to run forever in the background and handle all kinds of complex async flow. Execution stops when a request is done: no memory and data leaks between requests and easy to reason about.

In practice you don't really need async, except for stuff like sending emails and heavy IO. Laravel simply handles this by pushing jobs on a message queue and handling it via a worker process, but you can use any microservice of course (in particular a simple node app).

[1] http://reactphp.org/

Re: PHP 7 Virtual Machine

#25
post #6

It's always pleasant to see PHP occasionally get a positive moment in the limelight on HN. It's oft scorned yet powers a very large chunk of the web. With the work done on 7 it's also one of the fastest scripting languages around and deserves a little more credit if I'm honest.

PHP does not deserve most of the negativity it receives. It matured a lot recently and even though there are many alternatives tha probably can do better under some scenarios php still does what it does very well.

Re: PHP 7 Virtual Machine

#26

Earlier quoted context omitted.

nodejs is imho best suited for two groups of tasks: 1) APIs/programs relying on high concurrency and parallelism, especially where the handler(s) have to wait a lot for stuff like DB accesses 2) streaming (in the sense of websockets servers), PHP iirc can't even be used as a websocket server 3) Any API that can be implemented without needing too many async calls - you'll end up in callback hell or promise hell otherw…

There is a project called ReactPHP [1] which provides a nodejs-like event loop and async execution. However, I think the power of PHP is that it is not designed to be its own server, to run forever in the background and handle all kinds of complex async flow. Execution stops when a request is done: no memory and data leaks between requests and easy to reason about. In practice you don't really need async, except for…

I am by no means an expert on the subject but use Ratchet (http://socketo.me/) with proxying through nginx for my limited websocket needs. Works well.

Re: PHP 7 Virtual Machine

#27
post #6

It's always pleasant to see PHP occasionally get a positive moment in the limelight on HN. It's oft scorned yet powers a very large chunk of the web. With the work done on 7 it's also one of the fastest scripting languages around and deserves a little more credit if I'm honest.

PHP does not deserve most of the negativity it receives. It matured a lot recently and even though there are many alternatives tha probably can do better under some scenarios php still does what it does very well.

It is also quite interesting the PHP introduced many (or at least some of us) to the ideas of server-less computing already 20 years ago.

That's how I got started. I paid some small money for local ISP and got in exchange FTP user account and account on their shared MySQL Server. I would write my code and deploy via FTP. I believe some companies ran a cluster of servers, providing cloud like scalability for these deployments.

Re: PHP 7 Virtual Machine

#28
post #5

Earlier quoted context omitted.

HHVM was released in 2011, while PHP 7 was released in 2015. So perhaps in that extra time there was additional techniques, optimizations, and technology that allowed PHP 7 to stay comparable in terms of performance to HHVM.

There was a long time to catch up, yes. But HHVM did several big improvements to their JIT tech between then and now. PHP7 also rolled out with very little noise about stability, migration issues, etc. Not knocking FB at all, just noting the PHP folks did a nice job.

The PHP team is absolutely obsessed with backward compatibility. They broke surprisingly few things with PHP 7, and everything they broke was clearly documented.

You don't get to power a significant fraction of the world's most important websites if you break backward compatibility every few months.

Re: PHP 7 Virtual Machine

#29
post #10
post #8

Earlier quoted context omitted.

PHP is a whole lot more than just a templating engine. I think you would find that much more effort than is required just to make some templates.

Perhaps you can send me down the righ path? I want my users to be able to send emails from their iPads, and those emails would be generated based on templates. There will be many such templates built in, and eventually users will be able to hire web developer-type person to make custom templates. My thinking was that PHP is the most popular language for that sort of thing, so it would be nice if could support that. M…

https://twig.sensiolabs.org/

Re: PHP 7 Virtual Machine

#30

Earlier quoted context omitted.

PHP does not deserve most of the negativity it receives. It matured a lot recently and even though there are many alternatives tha probably can do better under some scenarios php still does what it does very well.

It is also quite interesting the PHP introduced many (or at least some of us) to the ideas of server-less computing already 20 years ago. That's how I got started. I paid some small money for local ISP and got in exchange FTP user account and account on their shared MySQL Server. I would write my code and deploy via FTP. I believe some companies ran a cluster of servers, providing cloud like scalability for these dep…

That's not what the server-less idea is about. You're describing a standard shared hosting.
Post reply on HN