PHP in 2017 - Rasmus Lerdorf @ WeAreDevelopers Conference 2017

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Applause] [Music] so welcome this is a very large audience I'm used to smaller crowds the slides are online at that URL talks up php.net Vienna 17 like all my other talks I'm on Twitter at Rasmus so I've been doing this for a very long time I am older than most of you in here it looks like this was me starting out hacking on a Commodore vic-20 I actually had a computer before that as well but I started doing my real development on the big 20 if you can call it that I dreamed of getting a 2400 baud modem back then this was pre-internet there was no web when I was doing this stuff and this Muslim world Zed modem downloading things in the 90s I played a lot with gopher which was kind of the web before the web and the world changed in 1993 when was a came out this was when the web hit the first graphical browser and as soon as I saw it I finally could explain to my parents where things were going I tried to explain Gopher to them they didn't understand gopher they said they would never use gopher but when I showed them the graphical web then they could start to understand and I knew instantly that this was what I had to do unfortunately in 1993 programming the web sucked this was a cgi-bin program written in C and it's C code where you have to go on you have to change the C code and recompile if you wanted to make even a slight change to the actual web application that was terrible a lot of people started using CGI p.m. this was a perl module for Perl to develop the web applications slightly better but the problem was first it was pretty damn slow you had to fork and exec a perl interpreter on every request this was way before mod Perl Plus you are still programming your HTML you still had to write Perl code to spit out HTML I didn't like that at all so PHP really what I wanted I wanted a simple templating language that was built into the web server so I didn't have to fork and exec another process but the web server itself could read HTML like any other but then do intelligent substitutions and you could inject your own code via C into it so the way I saw PHP and it this wasn't how it turned out but I saw PHP as a very thin templating system on top of business logic written in C and I provided a very nice API or so I thought for writing all your business logic and C and then just doing the front-end stuff just doing the actual display logic in the templating language the world disagreed with me nobody wanted to write C the web grew so fast that people completely ignored the entire C layer of this architecture they wanted to do everything in the stupid little templating language that I had written they wanted to write all their business logic in the templating language I was like what in people doing is this not a strictly typed compiled language or nuts you cannot write an entire application in a templating system you have to write the actual real parts the core of your business logic should be in a strictly type compiled language this is crazy but PHP grew and the number of people using the templating system was just crazy and part of this was because web grew so fast that there just were not enough developers to feed this insatiable hunger of this exploding web and all these pseudo developers who were tasked with developing the web they didn't want to learn see that takes a long time see use complicated you have to figure out pointers and complicated stuff like that this little templating language that has written people could understand that they could add one little thing to an HTML page and they could reload their browser and hey it worked they didn't have to compile anything it was just easy and then they started asking for more and more features and more and more things they wanted the templating language to do and I kept trying to fight back saying no no no this belongs in the business logic layer this should be done in C like no no we need it in the templating language and this is how we got PHP we got a templating language with business logic features kind of shoved up into it because that's just what people wanted and when people I mean it's the community that built PHP because I couldn't do it alone so people join the project in order to basically push these features that they wanted and that's what got us to where we are today and we're 2017 PHP 7 we have managed I think with PHP 7 to finally actually make it work so it is it is now superfast if you're still on php5 you really need to get off of it everything will go at least twice as fast once you upgrade and you'll use a lot less memory which means your server density you can you can spin out fewer AWS instances or whatever you're using you can shut off half your servers which is really really nice we didn't do it with a JIT like the Facebook folks did we basically started off in the JIT path but we know this we wrote a JIT well I didn't write it dimitri voltages and we know this with Dimitri's kit it didn't help out anything we could generate fractals really fast but WordPress and Drupal and all the other apps out there didn't speed up at all and with a lot of profiling we figured out we're just using way too much memory we're copying too much around so the focus shifted away from the JIT and just to reduce memory use and to make more efficient use of CPU registers and things like that and it worked amazingly we were actually surprised how well or how much we were able to save and how much we're able to speed up PHP seven simply by reducing the amount of memory that we needed and a drastic example of this is that this stupid little piece of code that generates a hundred thousand arrays of arrays in PHP five this takes 109 megabytes of memory in PHP seven with op cache enabled it drops to six Meg's of memory so you go from one hundred and nine to six this is a massive reduction in memory use and we ended up doing all kinds of other optimizations that you can read about the JIT it's still out there we're still plugging away at it it will probably make its way into maybe PHP 873 something it's not going to be in PHP 72 so it's not coming out this year maybe next year or the year after and then we could expect a significant boost as well as it is you can kind of see the progression 2009 was php5 3 so this is running WordPress the latest WordPress alpha release I just did these benchmarks a couple days ago running that on PC 5-3 154 requests per second running is on the latest PHP 72 that's coming out this year 540 requests per second right so at least for WordPress if you are still running PHP 5 3 I think the minimum version for WordPress is still 5 - but I can't even compile 5 - anymore I'm not sure who the heck is still running 5 - so if you're still on one of the PHP fives you're kind of lucky because you have this amazingly free boost coming very soon hopefully the FTO stuff it's a way of training your binary so getting a little bit extra boost out of it it's called feedback directed optimization it's a GCC feature and if you're really geeky and you have a very specific load so if you're just running one application on your servers you're not an ISP then you can tune your PHP to run that particular application really well by following these steps WordPress memory you can see as well with these versions that we used to need about one hundred and 40 Meg's of memory in PHP 5 3 to run WordPress now we need 15 and this is actually 410 CR 10 F p.m. processes running so it's the collection of 10 so each one is like 1.5 makes a memory but the server needs about 15 to run 10 processes now which is a huge drop almost a 10x drop in memory use the real world effect of this so this is graphs of Etsy's upgrade a couple of years ago from PHP 5 to PHP 7 so this is response time perk 95 response time or the latency the time between the first request hits the server and the first byte comes back it dropped from about 480 milliseconds to about 270 years or so a little over 200 millisecond drop in latency upgrading to PHP 7 CPU dropped as well pretty much in half so we were able to serve pages twice as fast in using half the CPU and memory use dropped from like 80 so Meg's down to 12 makes a memory which also meant that we needed a lot fewer servers and we could put more concurrent requests on the servers we had and we could turn off when I was testing the upgrade I started turning off servers and once I had turned off half our production servers the ops team were kind of wondering wait a second what's he doing and I started turning off more servers who like stop stop what are you doing you're taking down all our production servers are you crazy when I had taken down three-quarters of all our production servers the ops team said okay that's it you're not allowed but performance performance was starting to degrade but it didn't even that even when I turned off 70% 75% of our production servers it was still running faster than PHP 5 it has degraded from PHP 7 levels down close to PHP 5 but I was still slightly above PHP 5 performance levels so I thing of 75% of the production servers and that is the real key twice as fast the formants is nice but being able to turn off 75% of your servers imagine if the entire world did that right the impact that that would have so a little bit of math around that around 2 billion sites running the web currently and those two billion sites sit on about 10 million physical machines in data centers all over the world and PHP is on at least half of them so currently we're only at about 5 to 6% PHP 7 adoption on all those machines so on about 250,000 physical servers people have upgraded to PHP seven at three thousand kilowatt hours per year that cost about $400 in the u.s. at least plus data center cooling to cool all these servers were spitting out about half a kilogram of co2 per kilowatt hour at five percent adoption that saved about two hundred million dollars seven hundred fifty million kilowatt hours and we're spinning out about three hundred and seventy-five million kilograms less co2 just from five percent adoption of PHP seven if we can get to a hundred percent we can literally start changing the world and making the world a better place so damn it all right so if I can't guilt you into upgrading to PHP seven maybe I can provide a little bit of a carrot there are tons of really cool features in PHP seven you probably have gone through and seen most of them already so I'm going to go a little bit fast exceptions on fatal so most fatal errors are now actually exceptions so you can catch things so if you're doing an eval and you eval code call something invalid but has a syntax error you can actually put a try-catch around it and you can continue on or you if you ended up calling a method on a null which you end up doing all the time you can also recover from that in order to not break backward compatibility we shuffled the exception hierarchy slightly so that all your existing PHP 5 code will run exactly the same even though fatal errors are now exceptions they will still act like fatal errors because they will be uncaught even if you have a try-catch around things because we have introduced this sister class called an error exception that sits next to exception so you're not actually if you're catching all exceptions you're not actually catching you're these error class ones in your PHP 5 code so your PHP 5 code will run unchanged you have zero reason not to upgrade because all your PHP 5 code pretty much there are tiny few exceptions but all your PHP 5 code will run unchanged from PHP 7 return types this is the syntax : the type that the functions supposed to return if you get it wrong you get a type error exception which is fatal of course if you don't catch it cursive scalar types and strict scalar types meaning you can now put types on your arguments scalar types and the arguments coming into functions if you don't turn on strict types PHP will convert these types so you're guaranteed to get these types inside your functions and methods if you want to be really strict and have fatal errors if people get it wrong you can turn on strict types and you will get type thrown if people pass in the wrong things anonymous classes just like anonymous functions basically you can spin up classes on the fly and throw them away personally I've never had a use for this but there are framework folks that say that this is very important I am still a little bit dubious but it was easy to implement and and people smarter than me have said yeah it's it's useful when okay Colette's operator personally I like this one because you don't get notices for undefined variables so you can very easily put in default args so what this does is if this is non if this is set in the PHP sense of the word set it will return the first set variable so in PHP if you said something to know it's kind of like I'm defining it it's not considered set if it's set to null so in this case a or b be set to zero so this is going to return zero see your C or B C is 2 B is zero so you're going to get two now a X or C so ax isn't even defined the nice thing here is you don't get a notice on that it'll just go and return to in this case because a sunset X is unset C is the first one set I use it a lot for default arguments for like a get method variable and then default if it's not if it didn't come in via get or post then this should be the default instead of all the if m see if it's set like boilerplate code spaceship operator mostly because people were getting these comparison functions wrong for user-defined sort callbacks you can just use the spaceship operator and it will do the right thing in a sort callback and we've removed a whole bunch of PHP for stuff if you are still on PHP for tough your code is toast you can if you really are still in peace before I would suggest upgrading to PHP five six first because it's it'll then show you all the deprecated stuff you'll see all the warnings about things that were deprecated so go to the PSP five six get your stuff working on five and then make the jump to seven the next day there's some new reserved words so if you have classes named rule or string or resource that's going to break so fix those um 64-bit interpreters for various little educates things in here some of these were actually a lot of work but unless you're running all your stuff on Windows not a big deal to you this one will mess you up if you have some really complicated pieces of code something like this for example right so you have a dynamic function call a variable function call that returns a closure that returns an array you want to get this array element inside that array you have another set of closures you want to call it right you do all these things in one go don't do that but if you do you have to recognize in PHP seven this might behave slightly differently because now everything is left to right so it will start expanding this thing it'll expand this first I figure out well what is dollar food okay dollar foo is bar now I'm going to call a function name bar now that barbra turns in ray okay I'm going to look it up via the bar health index and it'll continue like that left to right the whole way through PHP five was a little bit inconsistent in how it handled these complicated expressions so if you have stuff like this go back and add in curly braces to make sure that hey I know I want this executed first it'll work perfectly in PHP five and they'll work in PHP seven and that way it will be preserved otherwise if you don't put these in an example like this for example we'll break going from PHP five to PHP seven because PHP five would expand this first and then use that value as the property name whereas in PHP seven this is the property name and then it tries to be reference to the array so you have to be careful that this is the biggest breaking change when I first started looking out on github and I downloaded all the application frameworks and PHP applications I could find I only found one out of about 40 or so one instance of an actual public project that got hit by this so oops sorry it's not as big a deal as you think and there are tools that can help you fix it all right some Unicode stuff a new crypto safe PRNG random in random bytes very useful if you're doing random stuff and you're trying to do the open SSL one of these other libraries this one takes the best randomness source on whatever platform you're on you can safely just call random int or random bytes 7-1 some additional features in there you can go and look at my slides I'm not kind of time to go through all of them and a couple of new things the break from seven zero to seven one is minimal a couple of new keywords we've dropped support for SSL v2 some of the normal things the biggest one I guess is M crypt M crypt is an ancient crypt so library that people shouldn't be using anymore if you're still using it start getting off of it soon because we're dropping support for it another project I've been working on static analysis can help you with this migration from PHP 5s PHP 7 first of all it'll catch really dumb mistakes so it's kind of hard to even spot this one it looks okay right but if you know this they probably meant to put the brace here right if count this greater than one as opposed to if count a greater than one right but static analysis this is syntactically valid right if a is greater than one this is going to be true count 2 is always going to be 1 right so it's always going to echo test no matter how many elements are in the actual array then this can catch it for you it can check your PHP doc comments so here can go through and say hey I bar in for M string argh you're passing in the wrong type as per your comments here so you can make those same and you can help you refactor you can drop it deprecated comment in on a function and you can very quickly catch all the colors you can very easily install it with composure composure require you can create a config where you set various configuration options and then just run bender bin fan and that will then scan your project directly we use it at sonnet Etsy so whenever we have this try system that basically runs all our unit tests and one of the things that runs is a fan scan of all the code so if you've made a stupid mistake the static analyzer will let you know and the docent unit tests also run before the push to production so it'll catch some mistakes before the hits production code it can also help you with type safety if you're trying to go towards the strict types in PHP 7 it can be daunting to change completely untyped code to strictly typed if you have stuff like this and you start doing strict right away and you toss in both types on the arguments and the return values it's going to be tough because you don't want your production code breaking for production users right so what you can do is you can use tag analysis and you can put in these types kind of like soft types in this sense and then catch it just to be a static analysis and once your static analysis is clean then you can start moving towards full strict types and you can do it gradually across your codebase alright 20 seconds left again slides are there talk to php.net vienna 17 i'm not going to have time for questions i don't think so I'm around I'll be around for the next couple of hours or maybe an hour or so catch me if you have something that you'd like to talk about other than that thank you very much [Applause] [Music] [Applause] [Music]
Info
Channel: WeAreDevelopers
Views: 68,268
Rating: undefined out of 5
Keywords: Rasmus Lerdorf, WeAreDevelopers, Conference, PHP, 2017, WeAreDevs
Id: fYTKm2oUzAg
Channel Id: undefined
Length: 24min 42sec (1482 seconds)
Published: Tue May 30 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.