Refactored PHP engine makes Wordpress 20% faster
news.php.net
news.php.net
We still do new projects in PHP and we couldn't be happier.
I concur, especially when frameworks like Symfony exist. Reading all this smack talk about PHP on HN is so alien considering how thriving the PHP community actually is.
Many have been where you are now, and then moved on to other languages to never ever look back. From what I've seen, the reverse is much less common.
I've probably written about 20x as much code in my life for fun, than I did to make money.
Guess I'm not a "real world people".
Though that ratio changes a bit closer to 3:1 looking at only PHP code I ever wrote. The "for fun" element was good times though, my first steps in server side programming :)
This is the case for any language. No matter how much you enjoy something, if a design choice you made (like choosing PHP, or Perl, or C++) means that you spend more of your time on the project, you've made a mistake. The purpose of a language is to remove as much of the incidental complexity of the project as possible, leaving only the (more enjoyable) intrinsic complexity.
I don't actually think that faults in a language matter that much if the people using it are competent. Both Javascript and Perl come close to PHP in terms of negative traits, yet a lot of good software was written with both. The same can be said about PHP, the only difference is that people on HN have very little idea about what contemporary PHP (language and software) looks like.
The problem with PHP is that it is a horrible language and there are plenty of better options in its niche. Those two factors combine to make PHP a nonstarter for programmers who are familiar with the other options.
I dispute that there is any good software written in Perl.
Do you even Linux? Have you ever installed anything? If you pay attention you will notice that lots of the libraries you are using for everything are written in Perl.
You can make a new project in Symfony or Laravel, sure, but you'll get that same niceness plus way more goodies if you use a popular Python or Ruby framework.
Can you name something that Python can do that PHP can't?
Please do.
$image_urls = [];
foreach ($images as $image) {
$image_urls[] = 'illos/' . $image['url'];
}
can just be this in Python: image_urls = ['illos/' + x['url'] for x in images]
And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to use PHP's strange "use ($a, $b, $c)" construct. Yes, that's a small thing, but PHP's way is a little bonkers.In PHP 5.3+ you can write:
$image_urls = array_map(function($image) {return 'illos/'. $image['url'];}, $images);
Not as concise, but I'd postulate easier to read for people not familiar with list comprehensions.In PHP 5.5+ there may be another way, but we're stuck with 5.3 in production for most clients, so I'm not up to speed.
> And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to use PHP's strange "use ($a, $b, $c)" construct.
Mmm, the debate of explicit or implicit scope? Explicit at least gets round those strange errors (hello Javascript) where you think you're referencing one thing... and actually referencing something else.
(javascript pun intended)
image_urls = images.map { |img| "illos/#{img}" }
Even better :) $image_urls = array_map(compose(papply('concat', 'illos/'), papply('lookup', 'url')),
$images);
This builds a function via composition: first lookup 'url' then prepend with 'illos/'. This function is then mapped over the array.Unfortunately relies on a bunch of functions which PHP doesn't include. Unfortunately PHP's stdlib concentrates on incredibly-single-purpose functions for, eg. string manipulation, while ignoring general programming constructs. Also, most of the really useful parts of the language aren't available as functions, for no real reason. In any case, we can define these things ourself like this:
// Function composition
function compose($f, $g) {
return function() use ($f, $g) {
return $f(call_user_func_array($g, func_get_args()));
};
}
// String concatenation. Unfortunately we can't write "concat = papply('implode', '')"
function concat() {
return implode('', func_get_args());
}
// Array subscript. I'd prefer to do this the other way around and write an
// argument-flipping function, but that's unnecessary for this example
function lookup($x, $y) {
return $y[$x];
}
// Partial application
function papply() {
$args = func_get_args();
return function() use ($args) {
return call_user_func_array('call_user_func',
array_merge($args, func_get_args()));
};
}
Regarding lexical scope, Python has ridiculous gotchas too http://stackoverflow.com/questions/5218895/python-nested-fun...PS: I still much prefer Python to PHP, but straw men aren't going to help ;)
PHP has type hinting and interfaces that makes it "java" like(it's a strength).
Python doesnt have interfaces but allows type hinting through decorators.
@typecheck
def gimmeFloat(a:int, b:list, c:tuple=(1,2,3)) -> float:
return 3.14On the other hand, <? ?>.
I really doubt that. In my experience there haven't been a single time when someone attacking PHP actually knew something about it that wasn't outdated by at least 5 years.
It's funny how difficult it is for people like you to grasp that the language and its ecosystem evolves every day, much faster than other languages. Just look at what you just said. How can someone have been where I am right now? They used a time machine? Or you are assuming that the language stopped evolving at some point, or never evolved at all in the first place?
Other PHP frameworks lack some or most of these features: some are either very opinionated and rigid (Yii, Cake) huge and sparsely documented (Zend 2) or just old and approaching abandonment (Codeigniter, Kohana).
To a newbie, would you recommend Symfony, or Laravel?
Thanks!
Laravel is basically a wrapper around Symfony, to make it simpler and easier. A newbie might prefer to use that, but at some point after feeling comfortable with the basics like MVC, ORM, etc. you will definitely want to move to the more professional Symfony.
Be sure to check out Jeffrey Way's Laracasts, it's a really good site offering tutorials mostly for newbies.
The Yii programmers designed it with performance in mind. I can understand that you find it opinionated, but in my opinions the pros outweigh the cons.
The only worthwhile point I still see in favor of Yii is its ORM can generate fewer, albeit more complicated, queries when eagerly loading nested objects. (OTOH, I encountered some ugly pagination bugs last summer when doing that...)
Just went to the Symfony site for my first time, to have a look. OK, I'll install it ... requires use of Alpha software (Composer) to install? Also, they tell you to pipe that script straight through PHP - don't appear to be any sha hash sums given or anything. Doesn't seem terribly mature and well-designed so far.
Profile Drupal, WordPress and the other heaviest users and look for the big wins.
Edit: This comment comes off as me making fun of PHP, when I simply meant to say that tools can make something effective but what underlies an effective work environment can still be crap. I don't think PHP is "crap," but at a certain level of complexity its easier to get the "average developer" to be effective using another set of tools.
How do you generate 211 pages per second on Wordpress to begin with? My server does page generation for my own custom-built blog in ~15ms, but takes a whopping three seconds for a single Wordpress page. I know it's somewhat offtopic and it's about the relative results, but what hardware is this?
This makes PHP much, much faster. The only time the files are recompiled are if you restart your webserver, or if you modify the .php files.
I'm not talking about static html generation, that's another thing all together.
Because it hit some sweet spot that WP blew over for your host specs? Either memory, number of queries, etc?
You really can't judge it based on that hardware. Of course it runs slower then your "custom" blog... it is probably orders of magnitude more complex.
Also you haven't mentioned what platform you are using. I don't know if those netbooks run linux or windows, but if you are trying to host this on a desktop version of windows with something like Xampp it is really incomparable as well.
But great work on the PHP engine!
Most Wordpress sites use a caching plugin like WP Super Cache or Varnish-type setup if they get decent traffic though.
Also, CI out performs Symfony in the web framework benchmarks: http://www.techempower.com/benchmarks/. I certainly would never equate Symfony to "real speed".
So instead of just saying their Symfony benchmarks are bad, submit a pull request to fix whatever you think is wrong so they can get more accurate benchmarks next time.
Also their tests are run without caching for a reason. It's not a test of the language/framework if they just use whatever language to generate a static/cached file and serve it with nginx.
> Also their tests are run without caching for a reason. It's not a test of the language/framework if they just use whatever language to generate a static/cached file and serve it with nginx.
Haha lol, so the tests are explicitly meaningless. I guess I'm done here then.
In my own benchmarks i've noticed all that class loading and instantiation slows things way down, even with an opcache. I find that a namespaced procedural / functional architecture performs much better, but no PHP framework works that way.
According to https://wiki.php.net/phpng, they benchmarked against Wordpress 3.6 (the current version is 3.9). I couldn't find anything about the Drupal benchmark, but it could be a simple "Hello world" for all we know.
Drupal's big two issues are bootstrapping drupal, because all those module hooks stack up quick, and the sometimes large amount of queries run to generate a page. Drupal 8 has gotten better about not loading half of the world when a blog post is loaded, but 7 is just a wall of functions.
I really don't understand people's aversion to database tables. I have a join, the world is ending! Pay attention to your indexes and 9 times out of 10 everything will be fine. For that 1 other time, there's Varnish.
As far as Wordpress, in my experience the number of db queries is really a bigger problem than the PHP processing. A factory-default install with no plugins runs 30 queries on every home page load. With a fancy theme and a few plugins it can be over 100 queries per page! A caching plugin is pretty much essential for any Wordpress site.
The linked email in turn links to the PHP NG page (https://wiki.php.net/phpng) on which the version number mentioned is 5.7.0-dev
http://grokbase.com/t/php/php-internals/12bvegp9cv/hhvm-and-...
But at the rate PHP's release cycle has accelerated (remember that 5.3 dates from 2009...) it's entirely likely that the trend will continue. And more hosts are offering up-to-date PHP versions as an option.
I still see a future for Zend PHP.
Heck, Python 3 hasn't even replaced Python 2 -- and people will dump PHP for Hack? A language which doesn't even have a community at the moment, it's 99% Facebook people.
Perhaps because some on HN are computer scientists, so to convince them it takes actual numbers and not some anecdotal evidence of what you personally use.
Judging from all available data sources, you are an outlier.
HHVM doesn't have that large a community (mostly FB people), is not installed in the overwhelming majority of hosts, still has compatibility issues, has few posts about it, there are very few mentions of companies using it, and, for what it is, has been largerly ignored in the whole PHP community (forums, etc).
Any other examples of it panning correctly?
In any case, let's check back in 2 years. I doubt Hack/HHVM will have more than 20% adoption even then. Criteria:
Number of hosting providers supporting it. Number of posts on HN from startups using it. Number of relevant community (forum and blog posts, contributors etc) Number of new projects written for it (GitHub) Number of new books appearing for it. Rank in the Tiobe programming language index.
And then goes on to say:
>HHVM doesn't have that large a community (mostly FB people), is not installed in the overwhelming majority of hosts, still has compatibility issues, has few posts about it, there are very few mentions of companies using it, and, for what it is, has been largerly ignored in the whole PHP community (forums, etc).
With zero references to any data.
The difference is that I gave objective and easily checkable statements.
References? I referred to specific items (hosts supporting it: just check the top 10 shared hosting providers), mentions of companies using it (how many have you seen on HN?), compatibility issues (those are documented on the project page), etc.
All of those are references to data sources you can actually check. I'm not going to crunch the numbers for you, but unlike the parent, you don't have to take my word for it.
Pointing to the data themselves is actually more scientific than the "references to data", if by that you mean some websites and news sources feeding you with ready made data points ("20% of developers are thinking of adopting HHVM, we know, we asked 100 of our pals").
a) it's run developed by a company whose policy is "move fast and break things". I have seen the result of this mantra first hand in their fucking terrible Facebook "api" where something breaks every time anyone anywhere in the world farts.
b) the number and nature of incompatibilities are too vast.
c) their intention is pretty clear with "hack" - they want a php-like language but not php. That's fine they can do that but I won't use it.
Wordpress 3.6 – 20.0% gain (253 vs 211 req/sec)
I have a few enterprise sites that I am constantly looking for ways to optimize for speed: DNS, CDNs etc. This looks like an easy win.
They could name it PHP 7 to avoid further confusion.
In addition, skipping a version number also creates confusion. If they were going to go this route, they should have done it a long time ago (around 2010-2011).
http://www.slideshare.net/andreizm/the-good-the-bad-and-the-...
In the internals all of the zend_hash apis have been updated so it may have an effect on some extensions, though the core extensions can all be updated.
"we changed the basement trying to keep most of the building unchanged."
The "most" part made me wonder what obscure part of userland it would be.
Additionally there is also a way to sort out possible bugs in language specification, as differences across implementations are sorted out.
>>> an throw nearly unlimited money and engineering hours at the problem
They can, but they won't. Because it already works for them, so the amount of resources they are willing to commit to something that no longer gives any upside to them will be limited.
>>> Seems like a losing battle, but perhaps I am wrong.
There's no battle and this is not a zero sum game. HHVM will have its market and standard PHP engine will have its market.