News for hackers. Stuff that matters.
Re:Taking PHP Seriously by ddw on Friday October 14, 2016 @12:27AM (#12706136)
But program managers and CTOs and other non-engineers at a company care about scalability, performance, technical debt and quality, right? Let's not pretend that these don't matter once you've gone past the "users actually care about our app" phase, because they do and they affect the bottom line of a company. And IMHO PHP falters in these regards.
Re:Taking PHP Seriously by increment_i on Friday October 14, 2016 @12:37AM (#12706161)
At this point, I would have no problem arguing with a straight face that your choice of technology stack might be the least important factor in whether your business succeeds or fails. I don't mind if I get torched for this, it's just my current, non-Silicon Valley, non-substantiated opinion at this time (though I don't think it's without merit).
Re:Taking PHP Seriously by riprowan on Friday October 14, 2016 @03:09PM (#12710378)
> But program managers and CTOs and other non-engineers at a company care about scalability, performance, technical debt and quality, right?

Rarely. Mostly they care about meeting quarterly goals and budgets; and ease of finding inexpensive, more-or-less competent talent. In both of these, PHP excels.

I'm currently maintaining an app stack for a Fortune-100 company that, if I told you what it was, you simply wouldn't believe I was telling the truth. That's how out of date it is. "Scalability, performance, technical debt and quality" never entered into it. All anyone ever cared about was "does it get the job done and what does it cost to keep it running for another year as-is?"

Re:Taking PHP Seriously by bmj on Friday October 14, 2016 @03:27PM (#12710471)
I'd upvote this many time if I could. I am in the same boat--my team helps maintain a ten year old web application that is used by the largest companies in our domain. The application is literally the backbone of data used by these companies to make money. We have reliability issues, and sometimes clients get a little upset, but every year it is the same thing: how much do we need to budget for support?
Re:Taking PHP Seriously by TeMPOraL on Friday October 14, 2016 @04:32PM (#12710884)
> Rarely. Mostly they care about meeting quarterly goals and budgets; and ease of finding inexpensive, more-or-less competent talent. In both of these, PHP excels.

This. In my previous job, I was literally told by my boss, that they'd consider switching from PHP to something like Ruby or whatever, but PHP programmers are cheaper so that's why they stick with it.

Re:Taking PHP Seriously by ransom1538 on Friday October 14, 2016 @10:38AM (#12708340)
Performance? You need to update your act. PHP7 is 3x faster than python and now faster than Java 8 . The only people that can call php slow are masochistic c++ web hacks.

https://blog.famzah.net/2016/02/09/cpp-vs-python-vs-perl-vs-...

Re:Taking PHP Seriously by pritambarhate on Friday October 14, 2016 @03:19PM (#12710434)
This benchmark shows things a little bit differently.

http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

But I think, what's important to note is that PHP 7 has improved in speed department by a great deal.

Re:Taking PHP Seriously by Shanea93 on Saturday October 15, 2016 @03:46AM (#12713147)
It's probably worth mentioning that the regex-dna test time is kind of incorrect and provides an inaccurate view of what's happening.

Java-8 is using java.util.regex which is written in Java, PHP is passing the regex requests to it's own regex process which is actually a C package and performs a lot faster.

What we're actually comparing here is:

time(java.util.regex) > time(php compilation + c regex package)

Re:Taking PHP Seriously by igouy on Tuesday October 18, 2016 @02:58PM (#12737566)
> Java-8 is using java.util.regex <

No, the fastest Java program shown does not use java.util.regex

The fastest Java program shown uses com.basistech.tclre

> a C package and performs a lot faster <

You're welcome to contribute a Java program that uses the PCRE library --

http://benchmarksgame.alioth.debian.org/play.html

Re:Taking PHP Seriously by spronkey on Monday October 17, 2016 @05:00AM (#12723544)
PHP's execution performance is highly dependent on whether you are piggybacking the C implementations, or pure-PHP ones. That said, this is still a correct benchmark, if your use case involves a lot of regex.
Re:Taking PHP Seriously by igouy on Tuesday October 18, 2016 @02:48PM (#12737469)
Perhaps the problems are with the way the Java program is written and run?

Back in 2012:

"5) The idea is to help you understand that you aren't comparing what you say you're comparing.

If your intention is to compare time taken to grow a list, then shouldn't you start with lists that are the same size, and start with program heap that's the same size, and use the same max heap size?

        user+sys for your Java program = 20.56s
But change

        ArrayList<Integer> s = new ArrayList<Integer>();
to

        ArrayList<Integer> s = new ArrayList<Integer>(8192);
and run with

        java -Xms1G PrimeNumbersBenchmarkApp

        user+sys  = 6.9s
I don't think you're comparing what you say you're comparing."

http://www.famzah.net/download/langs-performance/java-discus...

Re:Taking PHP Seriously by tigershark on Friday October 14, 2016 @06:07PM (#12711489)
I don't care about performance. Unless we are speaking about orders of magnitude and my use case has an absolute need for performance. If I only cared about performance I would write everything in assembly optimised for every specific architecture. But strangely I'm much, much, much more productive writing in c#, Java, groovy, f#, ruby and whatever language is appropriate for what I need to do at a certain time. For sure I won't start a new project using a language in which writing such abominations as accessing the database in the presentation layer is not even discouraged, but it is actually encouraged and taken as an example on HN in this thread. Enjoy your marvellous php. But please stop the bullshit that pushed a lot of people to use that franken-language rather than using a better approach.
Re:Taking PHP Seriously by Shanea93 on Saturday October 15, 2016 @03:38AM (#12713128)
Most professional PHP developers I've anecdotally worked with use a Model-View-Controller pattern these days, where the SQL is abstracted away in the model under something like Doctrine2-DBAL, Propel2 or PDO. If I was hiring for a developer and they suggested putting raw SQL in the view layer, I would reject them. If I received a pull request from my team which did the same, I would reject it.

You seem unnecessarily argumentative about this, almost like you're angry and I really don't understand why. There really isn't that much difference between languages like Ruby and PHP to warrant this and almost anything can be expressed in almost the same way, the only real differences are syntactic sugars and the "flexible" type system.

Re:Taking PHP Seriously by ufmace on Saturday October 15, 2016 @09:51AM (#12713911)
This exactly. Never been a PHP developer, but I did get handed a PHP webapp to copy some functionality out of for a replacement C# webapp. I was a little surprised to find out that it was written in a rather Rails-like architecture using some PHP MVC library, I think it was CakePHP. Rails was a hit, and a great step forward in web development, so naturally every other language copied as much of it as possible, including PHP. There may be plenty of weird quirks about the language still, but at least the architecture is much improved.
Re:Taking PHP Seriously by sethrin on Saturday October 15, 2016 @09:07PM (#12716345)
Many/most PHP platforms these days do claim to be either MVC or Rails-based or both. CakePHP is not a bad example there. There are however a few other very large projects whose take on MVC is lacking to some degree. Drupal is not bad, Joomla is worse, and of WordPress the less said the better. Note also that those projects are listed in order of increasing popularity.

Modern PHP frameworks and tools are good, perhaps even excellent. Composer and the PSR-# efforts have spurred a renaissance in code quality and interoperability, and PHP7 brings some truly impressive speed improvements. For those of us who aren't stuck supporting legacy code, that is. One of these days I will be working with a language whose syntax I enjoy, but until then the language that puts the "sin" in "syntax" will (for better or worse) keep getting the job done.

Re:Taking PHP Seriously by vancouverwill on Monday October 17, 2016 @03:37PM (#12728716)
Performance is directly related to profit on consumer apps. See http://glinden.blogspot.co.uk/2006/11/marissa-mayer-at-web-2...

plus like you say PHP might be faster to get started with but becomes much slower on larger projects due to inconsistent error handling and language design.

Re:Taking PHP Seriously by jbergens on Friday October 14, 2016 @11:12AM (#12708589)
Funny that people complain about js performance. In this benchmark it was 3 times as fast as php7 and about 7 times as fast as java 8. Have not checked the details of the benchmark yet.
Re:Taking PHP Seriously by juliangoldsmith on Friday October 14, 2016 @11:50AM (#12708891)
It's worth noting that it's compiled JavaScript vs. interpreted PHP. With something like HHVM the PHP version would likely be a lot faster.
Re:Taking PHP Seriously by secoif on Saturday October 15, 2016 @01:48PM (#12714936)
Compiled JavaScript?
Re:Taking PHP Seriously by niutech on Tuesday October 18, 2016 @01:35PM (#12736829)
I think he meant JIT compilation.
Re:Taking PHP Seriously by icedchai on Friday October 14, 2016 @07:42PM (#12711859)
Looks like you're reading that wrong? Java 8 is listed twice. Java 8, when using the non-standard library version of the program is second only to C++. This is pretty much as expected.
Re:Taking PHP Seriously by igouy on Tuesday October 18, 2016 @03:08PM (#12737667)
> Have not checked the details of the benchmark yet. <

"Will your toy benchmark program be faster if you write it in a different programming language? It depends how you write it!" ;-)

Re:Taking PHP Seriously by magic_quotes on Friday October 14, 2016 @10:04PM (#12712407)
> now faster than Java 8

Don't trust everything you read on the internet, run the benchmark yourself and see if that result is actually reproducible. (Depends on the heap size.) There is also a "non-std lib" java test case, which doesn't generate as much garbage and, of course, performs much better.

Re:Taking PHP Seriously by yxhuvud on Friday October 14, 2016 @03:24AM (#12706582)
Managers caring about technical debt? You must live in a parallel universe. They may care about maintenance costs, but that is not really the same thing.
Re:Taking PHP Seriously by ddw on Saturday October 22, 2016 @06:47AM (#12768189)
They don't until things break, your app can't handle the amount of requests coming in, can't insert and fetch data in a reasonable amount of time, etc.

It's at this point that shit falls apart and the manager starts to care about these technical choices and all of the time and money that will be needed to be spent to rewrite.

Call it maintenance costs if you want but those costs are directly affected by the technology decisions you make.

Re:Taking PHP Seriously by novaleaf on Friday October 14, 2016 @09:44AM (#12707993)
the end result of technical debt ==> maintenance costs makes it same enough.
Re:Taking PHP Seriously by GFischer on Saturday October 15, 2016 @08:18PM (#12716229)
Looking at things from the other side: being a manager and trying to sell projects to reduce technical debt is really freaking hard in a world of short-term outlooks and revolving door of CEOs that want to improve numbers this quarter or the next, not a few years down the road.
Re:Taking PHP Seriously by sqeaky on Monday October 17, 2016 @10:28AM (#12725290)
This is entirely true, but I have never worked with someone beyond the leader of my immediate who though the same. Most managers don't care what cruft is in there when it ships.
Re:Taking PHP Seriously by jwatte on Friday October 14, 2016 @12:45AM (#12706185)
The scalability of PHP is great, because each request is fully independent. This is like the Amazon lambda model. You /have/ to put your state in some storage back end, network attached RAM or such. This is a scalability best practice!
Re:Taking PHP Seriously by haimez on Friday October 14, 2016 @01:01AM (#12706226)
Yeah, but you also have to fork a whole process per request to do it.

Process fork, CoW overhead every time you mutate a page, and a full OS thread per request. Oh, and let's not forget negotiating a new database connection per request.

I think by the time you've added up all those overheads, you're not off to a scalable start. It's possible to work around the limitations, but it's not easy.

Re:Taking PHP Seriously by bartl on Friday October 14, 2016 @06:48AM (#12707229)
"fork" is not a major problem in PHP. In Drupal, every single request compiles a file "common.inc", of several thousands of lines of PHP code. That is what slows it down. It's remarkable that PHP still manages to do that in just 100ms.

In Zend Framework it's slightly better because it includes an autoload option, which implies only PHP files that are actually used by athe request, get loaded. That way the overhead is "only" 50ms.

Re:Taking PHP Seriously by ransom1538 on Friday October 14, 2016 @10:43AM (#12708378)
Wow. Is this comment from 2003? Uh. Why don't turn on opcache [1]? PHP7 is fast. Real fast [2].

http://php.net/manual/en/intro.opcache.php

https://blog.famzah.net/2016/02/09/cpp-vs-python-vs-perl-vs-...

Re:Taking PHP Seriously by igouy on Tuesday October 18, 2016 @04:21PM (#12738285)
> PHP7 is fast. Real fast [2]. <

You need a lot more than a "Sieve of Eratosthenes" code snippet to back that up :-)

Re:Taking PHP Seriously by raarts on Friday October 14, 2016 @10:10AM (#12708157)
> In Drupal, every single request compiles a file "common.inc", of several thousands of lines of PHP code.

This only proves Drupal is slow.

Re:Taking PHP Seriously by mtberatwork on Friday October 14, 2016 @07:45AM (#12707458)
> Yeah, but you also have to fork a whole process per request to do it.

Eh, any PHP developer worth their salt is implementing PHP-FPM. The days of forking expensive Apache processes have long been over.

Re:Taking PHP Seriously by xorcist on Saturday October 15, 2016 @05:38PM (#12715761)
The whole reason your Apache was (kind of) expensive to fork was PHP. You've only moved that forking to the PHP-FPM process.

But that said, forking processes is not really a problem unless you do really long lived connections (such as longpoll handlers). Many other languages do that. Not many other languages have kept the CGI-like request model that PHP has, though.

It encourages things like parsing code or even opening database connections on every request, unless you cache them. (Which you probably do if you are a PHP developer. But it's not always as automatic as one would hope. Have you checked your application still fits in the cache you set up?)

Re:Taking PHP Seriously by codedokode on Friday October 14, 2016 @05:25PM (#12711204)
And even whey they were not over yet there was no fork for each request. A pool of workers was forked beforehand, and each worker could handle requests one by one without restarting (only PHP environment is cleared, OS level process is not restarted).
Re:Taking PHP Seriously by justinhj on Friday October 14, 2016 @01:22AM (#12706270)
It is easy if you are just willing to spend more money on servers. Often it's worth it.
Re:Taking PHP Seriously by collyw on Friday October 14, 2016 @03:03AM (#12706522)
Its also a problem that has been solved a long time ago and is well understood. Unlike trendy microservice architectures....
Re:Taking PHP Seriously by haimez on Friday October 14, 2016 @01:28AM (#12706286)
Only if you extract a ton of value per user or can serve a huge number of users per machine. Otherwise, upping the number of servers by an order of magnitude will start requiring an operations team to maintain.

That was a pretty common truism 10 years ago, but machines haven't gotten faster at the same rate lately.

Re:Taking PHP Seriously by nrser on Friday October 14, 2016 @04:15AM (#12706737)
it's the "good problem". and the good problem can always be solved, though lack of reliability can seriously hurt your growth. but that doesn't mean that it's as easy as people make it out to be.

i wrote and ran a big php app (Zynga's Mafia Wars). this is just about the app server (apache + php side), single-master MySQL will give you far greater problems at that scale.

everyone is tearing away adding features, and the code just keeps getting bigger. everything includes everything else. so you can't just start fresh with every request, it takes way too long. so you use APC or whatever. now you have global shared state (and people start using it), but as long as no one really fucks it up that's ok.

php processes are always erring and dying in weird ways that no one can figure out, especially if anyone uses the half-baked OO stuff (circa 2008-9), and tracking down obscure php state errors ranges from difficult to impossible since you're never quite sure when or where something went wrong, but it works for most people most the time, as long as you remember to clear out the error logs so they don't get big enough to crash the box.

memory use still sucks at around 30M a process, meaning you can only have around 500 workers on at 16G RAM server, but it's workable. at least it's not rails.

because it takes a while to talk to even Memcache (go forbid you talk to MySQL) and do all your silly user updates (games are really write-heavy) you are taking a few hundred ms per request, so 16G mem servers (it's 2008) safely top out at around 500-600 req/sec, and i think would melt close to 1000 or so. remember, your throwing everything you have at growth and features so you're not really optimizing shit.

cool, just need more hardware. which is no problem. if you can get hardware. when you're co-located it takes forever to get new hardware online. not really an option. and even the F5 load balancers can only take so much. and there are issue with getting too many app servers talking to too many memcache servers. or something like that. after i left i think they saturated the data drops, which really puts you in a bind.

but that's not a problem now, with cloud services, right? except that those are not limitless either. i think FarmVille ran into a wall where AWS wouldn't / couldn't supply more instances (again, this was around 2009-10 so prob a lot better now). and those are still physical machines in physical datacenters somewhere that will have all the same problems and limitations and then some.

but you're going to have problems with any app runtime at that scale. and php's performance was an order-to-two or magnitude better than rails, and we never figured out how to get significantly complex and traffic-heavy java apps to stop leaking memory. though i'm sure you can. and you will! like i said, it's all solvable. hell, even MySpace didn't fail because of tech infrastructure.

what i'm saying is that php wasn't (and maybe still isn't?) particularly fun when throwing hardware at it doesn't work, and you end up losing a lot of the purity / simplicity of the model because it's too damn expensive. ffs, Facebook re-wrote the runtime. that's what it took for them. and my friends there tell me it's pretty much like writing java at this point. it's a fine choice, but i'd rather not use it again. had a much better time with python before javascript ate the world.

Re:Taking PHP Seriously by dakull on Friday October 14, 2016 @05:11AM (#12706908)
>php's performance was an order-to-two or magnitude better than rails

Again PHP (the language) vs. Rails (the framework).

What framework was that `big php app` using?

Re:Taking PHP Seriously by chriswarbo on Friday October 14, 2016 @05:51AM (#12707039)
> What framework was that `big php app` using?

PHP is a framework. True it's not a particularly nice one, and some people build even more layers on top, but it comes with all manner of HTTP/url/DB/etc. stuff out of the box. It's also a templating language (that's what the "<?php" tags are for); although, again, not particularly great, and some people layer more abstractions on top.

Re:Taking PHP Seriously by bigtunacan on Friday October 14, 2016 @09:20AM (#12707852)
In the sense of comparing PHP and Rails, then no PHP is not a framework. Codeignitor, Laraval, Cake, Yii; those are PHP frameworks and fair comparisons to Rails.

I can (and have) just grabbed Rack and rolled most everything myself in Ruby and it has way less overhead and is much more performant than Rails. Ruby also has it's own templating language; ERB is part of Ruby core.

So comparing PHP to Rails is a bit apples and oranges.

Re:Taking PHP Seriously by nrser on Friday October 14, 2016 @11:45AM (#12708854)
it's a business decision comparison, not a technical categorical comparison. you need something to receive http request and return http responses, and you're comparing different popular (because hiring, training, and available community / support resources) ways to do that. they might be apples and oranges but at that level you're concerned with comparing fruits.
Re:Taking PHP Seriously by bigtunacan on Friday October 14, 2016 @03:02PM (#12710340)
In this case it was a technical comparison; the original poster stated, "php's performance was an order-to-two or magnitude better than rails".

If you are making a technical comparison then it needs to be at the correct layer of abstraction. If we were to compare performance of Laraval and Rails that would be a fair comparison.

If we are comparing on performance then PHP should be probably be compared to Ruby+Rack since that is sort of the lowest common denominator.

I'm not dogging on PHP here either. Even comparing at the correct level; PHP is still faster, but lets make sure we are making the right comparisons.

Re:Taking PHP Seriously by nrser on Friday October 14, 2016 @04:26PM (#12710838)
i am the original poster.

i was clarifying the compassion.

Re:Taking PHP Seriously by brightball on Friday October 14, 2016 @09:19AM (#12707849)
Very true. It's basically an interface to a C framework.
Re:Taking PHP Seriously by nrser on Friday October 14, 2016 @07:53AM (#12707493)
as the other commenter said, php is a web framework... and it's what we were using. it's actually more of a web framework than a language in my opinion (or at least was at that point). it's centered around receiving http requests and writing http responses. the article mentions this in fact.

it was a huge pain to try and get php to do anything else. it was totally unpractical to do the kinds of back end processing that we needed (since the database was pretty much off limits during a http request)... long running processes with hundreds of millions of objects were a no-go. believe me, we tried. which meant you had to sync all your logic into Java or something else that could handle the job. which is really error prone when you have a bunch of people moving fast on something.

one of the greatest things about php is that it's a super minimal focused framework. it's also one of it's major short-comings when that model no longer suffices.

you can layer something else on top of it, but the stuff available at the time certainly didn't help the performance or memory characteristics.

Re:Taking PHP Seriously by jliptzin on Friday October 14, 2016 @12:12PM (#12709045)
I think I sat next to you at zynga back in 2008 and remember your php struggles vividly.
Re:Taking PHP Seriously by nrser on Friday October 14, 2016 @04:30PM (#12710870)
hey Josh!
Re:Taking PHP Seriously by justinhj on Friday October 14, 2016 @02:36PM (#12710191)
I feel your pain, I also worked on a large MMO style mobile game backend, but my situation was a lot better because as you say AWS is a lot more mature at this point.

Dealing with limited resources such as MySQL and Redis is a problem you still have to fix when you move away from PHP though.

As for the Facebook runtime, for us it was a case of drop in HHVM, fix a handful of issues and get a 4x or 6x speed increase for free. You only need to change the way you write if you move to Hack, but I think I agree with you that's probably getting to the limit of the effort reward tradeoff before you rewrite in a different language.

Re:Taking PHP Seriously by niutech on Tuesday October 18, 2016 @02:02PM (#12737059)
Why didn't you choose Python/Django instead of PHP then?