6 ms·
Wow. I'm honestly surprised by the amount of people (on the HN!) in 2020, thinking PHP is some pre-historical language clearly inferior to... I'm not even sure
by krick 7y ago
Wow. I'm honestly surprised by the amount of people (on the HN!) in 2020, thinking PHP is some pre-historical language clearly inferior to... I'm not even sure what. JS? That would be funny.
(It feels like I'm defending PHP now, which is feels weird, because I can go on for hours talking about the stuff I hate about PHP. But there is a difference between hating it for problems it actually has, and just not treating PHP as seriously useful modern tool which it definitely is.)
That aside, I cannot really treat seriously author's recommendation of Amp, ReactPHP and such as a solution for async. Don't bring up HHVM either. There's no real solid support for async/await in PHP, not even in the form Python has for quite a while now. And for me, it might be the biggest problem it has right now, which seriously hurts in some applications.
- CiPHPerCoder 7y ago> There's no real solid support for async/await in PHP, not even in the form Python has for quite a while now. I'll second this. Async/await support in PHP is at best an ugly hack. I don't know if we'll ever get first-class async/await support since there is no event loop in the PHP runtime, and because of how PHP works (build and teardown on each HTTP request). > And for me, it might be the biggest problem it has right now, which seriously hurts in some applications. What problem are you trying to solve where a lack of async/await would help?
- krick 7y agoI've encountered dozens, maybe hundreds of problems where it was actually something that would matter. Here's one example. Consider you need to process lots of requests, that require making multiple requests that take a long time to finish (like 10-30 seconds) and you need to do it nearly in real-time. Given there's no sane multi-threading in PHP as well, you end up building your own parallelism support, which requires running lots of workers. Now, every of these workers does some pre-processing, makes a requests and waits for multiple damn seconds, to get the result back, make some computations and get to the next job. Consequently, to handle the same number of requests/sec you need much more workers, which has a lot of overhead, which results in needing more servers. Sometimes you can use CURL to just make multiple similar requests in parallel and call it a day, but in practice I rarely could make use of it (consider that service you need to call might require some fucked up protocol, like SOAP, so you best option would be to rewrite SOAP client using CURL with parallel requests, which is not fun at all). At that point you really start thinking some (any?!) other language would be a better fit for the application, but you have tons of very domain-specific business logic written in PHP that you'd need to rewrite for that app, as well as a team of PHP-developers that are not necessarily ready to learn whatever you have in mind, sooo...
- meritt 7y ago> to handle the same number of requests/sec you need much more workers, which has a lot of overhead When doing multiprocessing, it's advisable to fork() instead of creating fresh processes (or launching them in containers etc). As long as you preload the necessary libraries/modules in the parent process before the fork, children will reference the same memory in a copy-on-write fashion. It keeps overhead extremely low. This [1] article is for the Unicorn (ruby) webserver but the way it explains forking, signals, and pipes for inter-process control it's absolutely illuminating. These techniques are applicable to any unix-based applications, including php daemons. [1] https://thorstenball.com/blog/2014/11/20/unicorn-unix-magic-tricks/ https://thorstenball.com/blog/2014/11/20/unicorn-unix-magic-...
- krick 7y agoThanks, that's a nice idea. Kind of hard to implement in the setup I'm thinking about right now, but, still, that never occurred to me, so this is something to consider. But, of course, it doesn't replace proper async/await. First of all, there are other situations where this solution wouldn't apply. And even in described scenario it isn't ideal. For starters, pre-loading everything before fork is really easier said than done: quite often data you need to fetch depends on the result of request, but just so happens to be very much reusable between multiple jobs. Then, it complicates the code quite a bit, makes to constantly keep in mind across the whole codebase things you wouldn't really want developer to think much about to start with. Additionally, it makes DevOps harder as well: people want to rely on LoadAvg (which is very unreliable metric, but explaining this to people every time is not what makes for a friendly environment) and multiple jobs doing nothing just waiting for I/O to finish sky-rocket it. Then some DevOps tools (you don't necessarily know about because of department communication) try to be smart by relying on loadavg and start actually breaking things.
- godman_8 7y agoIt is a hack, but it works well if you follow the rules. We've deployed stable and scalable APIs using PHP(Laravel/Swoole.) We would have loved to use something more fitting like Go but the time to MVP would have been much longer. While not perfect, it's been great to develop with. Using production code, it provides us ~5x rps (over php-fpm+opcache,) lower latency, better efficiency, and better scalability. However, if variables are set outside the event loop they will not update, so we had to add some additional tests to help avoid this.
- rawoke083600 7y agoI hear you.. I think it has just became the popular millennial thing todo to bash php.
- buzzerbetrayed 7y agoJust like it's become popular to attribute things you don't like to millennials, when you have no idea if they are millennials or not.
- deleted 7y ago[deleted]
- zelphirkalt 7y ago> Wow. I'm honestly surprised by the amount of people (on the HN!) in 2020, thinking PHP is some pre-historical language clearly inferior to... I'm not even sure what. JS? That would be funny. Erm, well, if I compare with any language, that has a thought through type system (PHP: generics missing, no base type one can use instead), proper closures (https://nullprogram.com/blog/2019/09/25/ https://nullprogram.com/blog/2019/09/25/) and actually consistent standard library ... Yes PHP is still a kind of prehistoric language. Basically one cannot do FP properly without proper closures and that forces people to the other end, usually OOP, but that is terrible in PHP as well. Some kind of patched on top "here you have classes" kind of OOP basis, without generics. Great. And then all the bad practices PHP encourages, with its hundreds of PHP open tags and PHP close tags, intermingled with HTML and JS, which you can see in many popular open source PHP projects (especially Wordpress plugins lol). Sure, you don't need to do that, but then again PHP gives you the gun to shoot yourself in the foot with. Basically you can throw away all the "output HTML immediately" stuff of the language, use a template engine and you will be better off.
- pas 7y agoI have a good friend, full time full stack dev for the last 2 years. PHP + JS, on a 2 man team/project/product. He is the epitome of the late bloomer programmer (bachelors in CS and masters in econ math), they started using composer 3 months ago. No package.json yet! No make file, no linting, no CI/CD, no deploy. Though they feel that it'd be great to bundle JS files. No templating engine either, though they are doing AJAX, so no <?= spaghetti. Probaly on their next project they might venture beyond PHP. Who knows. We can't force people to start with Rust. :|
- zelphirkalt 7y agoHa, well, we all started somewhere. My first website also use PHP, although I never did the spaghetti, not even as beginner programmer, but then again I learned it differently in school and also did not make use of JavaScript on that website ... Ah but actually that's not true, my first website was HTML, CSS, JS on a file hoster and uploading in the correct sequence to update the links in the files. > We can't force people to start with Rust. :| Yep, we cannot and should not force. Perhaps Rust is also quite difficult for beginners to use, even if with that comes great learning. I consider it a fine language. I only wish it had proper tail call optimization. If it had that, I would probably start a project in it tomorrow. sigh. Good luck to your friend, hopefully they will dip their toes into something beyond PHP soon.