PHP in 2018 by the Creator of PHP

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Sweet. I've read the slides a couple times before (they show up in some google searches I've done) but never watched the talk. Glad I did, he gave a lot of extra explanations on top of the slides that I didn't get before.

πŸ‘οΈŽ︎ 8 πŸ‘€οΈŽ︎ u/MaxGhost πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies

Besides the very interesting tidbits about how PHP 7.x is being optimized, the best take away was Phan - the static PHP analyzer.

πŸ‘οΈŽ︎ 18 πŸ‘€οΈŽ︎ u/inkit πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies

I like how he owns up to screwing up the original design (~5:15) and admits PHP isn't focused on breaking backwards compatibility nor the 80% of the web that has some component of PHP code. Flak, a consequence of owning the territory.

πŸ‘οΈŽ︎ 14 πŸ‘€οΈŽ︎ u/tsammons πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies

This is really awesome. Thanks.

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/[deleted] πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies

That was really nice to watch because it was not only a walkthrough through the new features and known issues with PHP, it also was a journey back to my starting days with PHP.Wish there were more presenters like these catching up with PHP.

Edit: http://talks.php.net/index.php/PHP is the right place to go!

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/pr1nzvalium πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies

Where can I get the slides?

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/maxfontana90 πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies

I knew about DCE, but wasn't aware how clever it is. Can I assume that every redundant intermediate variable (like those introduced for readability) will be eliminated?

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/MorphineAdministered πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies

Still the king (we deserve.)

πŸ‘οΈŽ︎ 5 πŸ‘€οΈŽ︎ u/[deleted] πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies

Man, phan looks awesome. It's the kind of tool I need at work.

πŸ‘οΈŽ︎ 4 πŸ‘€οΈŽ︎ u/[deleted] πŸ“…οΈŽ︎ May 26 2018 πŸ—«︎ replies
Captions
my talk it's online there's always talks the peach net Twitter at Rasmus so I'm old older than I think everyone in this room maybe with a few or maybe a couple of exceptions one or two maybe but I'm turning 50 this year which is in the source world is quite old at my company where I work at that see I am one of the two or three oldest and the company in this business very in this a young business it's for young people mostly I started off hey here we have the other room coming good welcome I can speed up I started off in the 80s this was my first computer Timex Sinclair has like has 1k of memory the big block on the back is a 16 K memory expansion module and I learned to do a lot of low-level programming because that module was so big and heavy it would sometimes come loose so my program would go from having 17 K of memory down to 1 K instantly so I had to make sure my critical loop were in the lower 1k at all time so my code wouldn't crash and they could then repopulate the upper memory types of things we don't think about these days really but maybe with cloud computing and dynamic memory resizing and things like that maybe some of this stuff comes back we'll see vic-20 like many people dreamt of getting a haze northern so I could actually go online to interesting stuff it's been a lot of time sitting there watching Z modem download stuff this was the internet for me this was the web there was no web basically web started off slowly with gopher and in the early 1990s worked a bit on that and it was until 93 when we saw mosaic the first web browser first graphical web browser to come out that I really got into web development full time and that's when I started at PHP and that's where the PHP story starts and about mid to late 1993 or I started building websites the code of my early stuff looked like this so these are CGI C programs you can see HTML inside a c program any tiny the UX type of change wanted to make yet to recompile your C code and redeploy it and it was really easy to screw up your C code especially if you're handing off the visual designs of somebody else back then handing them a C program and asking a visual designer not to mess up C that didn't work so well so I needed a better solution than this because I hated doing the front-end stuff I've always hated doing front-end work I was always a back-end person so most of the web in 93 switched over to Perl CGI p.m. it's a perl module that lets you code CGI programs in Pro to me this wasn't that much better it just meant that I'm handing off Perl code to the UX person and asking them not to screw up Perl which might actually be a harder ask than asking me not to screw up see because Perl can be screwed up in so many interesting ways so I wanted something more like this I wanted my HTML to look like HTML I wanted to be able to hand off things to the designers in a way that they couldn't possibly screw up all right well they could still mess up HTML by me that's their job they should know the HTML part and I just wanted to give them a couple of magical takes that because add to their library of HTML that they knew and have them solve domain-specific problems using that and I basically give people a cheat sheet I say okay you know HTML here for this particular application that we're working on here are 12 extra fancy tags that you can use to pull in back-end data and do interesting stuff with and that was that was the birth of PHP it was a templating system for the longest time and I always resisted this desire to make it a language and call it a language to me it was a way of interfacing HTML and the backend C code that talked to all the backend systems the problem was though that people wanted to do more and more logic in the templating system nobody wanted to write C code and I couldn't convince people to write C code because the web was growing so fast and they weren't see developers in the world my idea of PHP never came to be my idea of PHP is not the PHP we have today my idea was for PHP to be a very well structured C API for the web where you write all your business logic in C a fast strongly typed language and you only do so that the visual logic that the display logic in the templating system but the entire world disagreed with me they wanted to do all the hard core business logic in the templating system and yes I had added some language like features to the templating system so you could have snippets of things snippets of a template that you could repeat through calling a function and you could do most sort of language like things but the intent wasn't to build business logic in that it was to make it a very rich templating system and my ultimate failure came when people started writing templating systems for my template existence and at that point I knew I had lost so having lost that battle and sort of given in the task then was to make okay since this doesn't start off as a templating or as a programming language it was a templating system now we have to switch gears and I have to switch gears and actually make this rather crappy templating language a good programming language and that has taken some years and there's a lot of legacy things in there because of that and PHP gets a lot of criticism because of some of these legacy features but we've always strived to not break back with compatibility because there's just so much code out there some people say up to 80% of all websites have some level of PHP on them imagine how big the web is and if we go and break 80 percent of it not cool so our latest thing was speeding up existing sites and speeding up the web we did that with PHP 7 and many sites will see a hundred percent performance improvement so double the speeds some sites will have even more than that sometimes some sites will speed up three to four times just by upgrading from PHP five to PHP seven and we did that by focusing on memory usage we started off trying with a JIT because Facebook's H HBM had shown us what could be done with a good JIT so hey let's let's write a JIT and we did and this JIT created fractals really really fast but it didn't speed up your WordPress site it didn't speed up your Drupal site it didn't speed up any real-world PHP sites out there so we abandoned the idea of a JIT and instead really focused hard on reducing memory usage and also improving CPU cache usage worked a bit with the Intel compiler team and they helped us profile and narrow down some of the places we were blowing away l2 caches at the CPU level and a lot of low-level things like that getting better data locality for data that we're moving around means fed stuff from the database don't copy it from the database buffer to another buffer to try to keep it all in one buffer and never moving things around same when you're calling functions don't make copy of the function arguments so a lot of things were done to make sure that we only ever put data in memory once and then always refer back to it and lots of other interesting tricks so here's a piece of code that makes a hundred thousand makes an array with a hundred thousand little arrays inside so the nest of the rate in PHP five this takes up a hundred and nine megabytes of memory PHP seven with no op cache takes about 42 mega bytes because of some of these low-level reductions we made in the hash table and hash table buckets but we also have an opcode cache by default now in PHP 7 which is a big chunk of shared memory where we can toss things in too and we're actually make use of the shared memory segment so when you have static arrays like this we copy it into shared memory and we store it as an array in shared memory once so each client or each process it's either in the nginx PHP fpm process or might be an apache child process with mod PHP loaded in it's actually only stored once in shared memory and all the individual processes don't have their own copy unless you change it if you make a modification to one of these elements then that element gets copied down into a local memory because that change may not be relevant to the other parallel processes that are accessing this memory that gets a little bit complicated because you have many different processes all accessing the same memory so you have to be quite careful and it took quite a bit of work to get to that stage but the memory reduction is dramatic in cases like this like going from 109 megabytes to 6 megabytes there's a huge huge memory reduction some of the other things we did lots and lots of optimizations across the entire code base and this this code at the time was 22 years old this code base now we're close to 25 years old making an old code base like this twice as fast without breaking backward compatibility is a small miracle I mean this is not an easy thing to do basically if you look at low-level instructions we're now doing the same and work without breaking anything in 1/3 the number of instructions that PHP 5 used to do the thing so basically it's like taking your code and saying delete 2/3 of it but make it behave exactly like it did before on the code base that's 25 years old good luck doing that on your own code base we still don't have a JIT in PHP 7 and we will probably revisit the JIT for PHP 8 so we still have this opportunity for a major speed boost all of the speed improvements in PHP 7 came from the memory reduction and the optimization that we did on the core we still have this opportunity to introduce a JIT so we may see another big bump all right so actual numbers here this is WordPress 4.8 running on PHP 5 3 5 4 all the way up to PHP 7 2 you can see we went from about 154 requests per second to 540 requests per second going from 5 3 to 7 to this FDO is kind of a special build of PHP 7 to GCC the compiler that we use has a cool feature called feedback directed optimization FDO and what that means it's kind of like an external JIT what you can do is you can build a learning version of PHP and then you can train it on your specific data and then you recompile it a special version you get a special version of PHP that is tuned directly for your particular workload so in this case I am training it for WordPress so you do make prof. 10 so you generate this profiling version of PHP you train it and easy way to do that it's called PHP CGI - T this is run this a thousand times and because the front page of wordpress pulls in basically all the word press through includes you don't need to hit any other pages for your particular stuff you may want to hit a couple of entry points into your application then prof clean and make profuse and that gives you the binary and that gives you this binary i used here which is about a to the 3 percent increase over the non profile the non optimised version and this is not a PHP thing you can do that for any Linux binary you can build an FTO version of your binary for your particular load all right what's more important than straight sort of performance single process performance is actually memory use and here we can see how it's gone down from in WordPress from 5 3 to 7 going from a hundred and forty megabytes of memory needed for 10 parallel processes serving up WordPress it's gone down to 15 that's another massive massive memory drop and it means if you're hosting stuff on cloud instances it means that you can pay for much smaller instances to serve up the same amount of traffic with PHP 7 so the request density of PHP 7 it's more than just the fact that PHP 7 is twice as fast it means that it's twice as fast and you can put probably six to eight times more load on that server so if you have say 80 instances in the cloud you could probably do the same work with 10 which is a huge huge difference at Etsy when I upgraded to PHP 7 a couple of years ago here is a graph this is perc 95 response time so latency with two servers running PHP five and two servers running PHP seven so the latency dropped from about 460 milliseconds down to 260 milliseconds so we cut off 200 milliseconds of latency on the production Etsy servers by upgrading with no code changes cpu per request so CPU usage got cut in half there abouts and memory went from about 80 megabytes down to 12 megabytes of memory per httpd process we're using apache in this case so it was a massive massive reduction in in hosting needs I was able to during testing I turned off 2/3 of my production servers at Etsy so the point where the the ops were screaming what's going on I mean you're turning off all our production servers stop it this is scary but I was showing them look we're serving up the same traffic it's serving up faster with only 1/3 of our actual servers and it makes a huge huge difference because they're around 2 billion sites on the web so the web is hosted on about 10 million physical machines right now and PHP very conservatively is on 50% it's likely much higher than that so right now we're at five to six percent of the option of PHP 7 so about 250,000 physical servers have upgraded if you start looking at energy usage for those at 5% adoption lots and lots of savings lots of less co2 being spewed out in the atmosphere but I would like to see go to a hundred percent there's really no reason not to upgrade to PHP seven the incompatibility is between PHP five and PHP seven are quite minor and it's easy to go back to your PHP seven and just look at some of your warnings and look at your notices if you're running clean PHP five code that doesn't spew out a ton of warnings and notices about deprecated things it's gonna be a very very easy upgrade to PHP seven yes if your PHP five code looks like PHP four code that's fused thousands and thousands of warnings in PHP five you have a bit of work to do but it's work that you should be doing because your code there's ancient them all right so please please please do your part upgrade to PHP seven I have a 16 year old son I would like for him to have a world he can actually live in for the rest of his life if you don't upgrade to PHP seven he will get angry at you alright so PHP seven - what's new so PHP 72 is the current version of PHP we are doing some initial DC and sccp optimizations which probably means absolutely nothing to you and I'll talk a little bit more about that in the next slide some of them more easily to understand features parameter type writing widening means that if you are extending a class you are allowed to loosen the research the restrictions in the child class so in this case the parent is saying this should be an array and here you're saying well I'm gonna extend it it still allows an array so it's still compatible with the parent but we're also allowing other types at this point it's for the F n function here in PHP 71 it would give you a warning it would complain about that and there really according to Liskov there really is no reason why you can't wide the type so that's one of the changes again this should not break your code if you're upgrading from 71 to 72 it just means a warning is gonna go away nothing else we're now allowed trailing commas everywhere we allowed that in a race before but now sort of with a nod to great JavaScript comma debate anywhere you have a list of things separated by commas and PHP 72 you cannot have a trailing comma kind of a minor feature there's an object type int now this basically allows you to say that something takes an object doesn't matter what type of object and something returns an object whatever type of object that might be we've also deprecated uncoded strings they still work for they will spew a warning it was kind of a weird legacy feature from ages and ages ago you could put in a string and if it didn't match a constant it would just be treated as a string even though it didn't have quotes around it and it still works because some code relies on that but it's gonna go away in the next major version of PHP so we're spewing out warnings for it now and you can pass extra headers to the male function as an array again quite a minor feature we've also added argon to I which is a hashing mechanism and probably the biggest feature of 72 is we've moved away from m crypt completely now and everything is now based on Lib sodium which is an encryption library M crypt is in heavy you still but it hasn't been updated in about eight years its unmaintained an unmaintained crypto security library is a really really bad situation to be in so we're now using a maintained lip sodium library there's a really good online book about lip sodium here if you want to learn more about it but all your encryption needs can basically be solved through sodium calls now things that may break your code like I said we've moved completely away from M crypt this already warned in PHP 71 saying this stuff is deprecated it's gonna go away and it's now completely been removed in 72 that's probably your most the most of your work upgrading to PHP 72 is probably be encrypt related and a couple of other really old features have been removed that might break your stuff or at least be warnings now all right so I promised I'd talk a little bit about DCE and sccp so DC e stands for dead code elimination another term we use is escape analysis and sparse conditional constant propagation what this all means is that we will go and look at the code and see if there is anything that doesn't need to be there before we cash the op codes in the OP cash so if you write code like this equals 1 return 0 what's the point of this a equals 1 here like absolutely nothing right the way PHP handles global variables you have to declare Global's so this can have absolutely no side effect and that's where escape analysis comes in we analyze this and see is there any way for this dollar a variable to escape this context and there isn't so in PHP 7 1 this would actually do exactly what you asked it to and it would assign int int 1 to dollar a and return 0 and that's the opcodes that would get cashed in PHP 7 2 we completely remove that assignment so that a equals 1 is as if it wasn't even there because what gets cashed in the OP code cache is just return 0 so every subsequent request after the first one won't even see that and it has no impact on the code whatsoever we can try more complicated things so in this case we're passing in four strings we're catenate and together putting that result in X then we overwrite that X variable and we return X and here PHP 72 is smart it still receives the variables but that's actually a no op it doesn't do anything it so that entire function here is just replaced with return 0 you can also see the X variable went away because actually equal 0 return X there's no reason to make that assignment either because that whole function reduces down to just as if you had written returns or in your function which obviously runs much faster than having to execute all these op codes in PHP 7 1 you can try to trick it so in this case I mean this is legal PHP B equals a plus equals 3 and PHP 72 is smart enough to see that there's absolutely no reason for B to be in here so B is eliminated so we just add 3 to a and return that some things that aren't you can trick it a little further and 72 doesn't quite have the smarts yet in PHP 73 we're making this even smarter so in this case you just do the assignment here and then return a PHP 71 couldn't quite figure this case out in 7 3 it can also figure out object stuff so in this case it does escape analysis one level up to figure out is there any point in this instantiation of object a and it looks at the object and sees well we're just assigning a property but nothing is happening with that property there's no point in any of this just get rid of it so this entire function gets reduced to just it as if you had written return dollar x if you added the structure to it then suddenly escape analysis say wait a second that the structure might do something and in this case we can't eliminate instantiating the a object because in case the destructor does something and we're currently only going one level up to check to see if they're constructors and destructors if there is a function that will get called on the object getting that's constructed or destructed then we know hey there's a chance this will escape and we can't reduce it down to something simpler stuff like this here PHP 73 is slightly more efficient than PHP 72 here you basically go through we figure everything out and this function with this function ends up just being returned for right if you do the math on this thing you don't need to create and because this stuff will always return for nothing else it also understands conditionals and this one's kind of cool if you walk through it you will see that nothing ever gets done other than return zero here no matter what X is because it's only looking at a zero this 1 & 2 doesn't matter so the if X doesn't matter this function will always return zero and the escape analysis and sccp is smart enough to reduce all this down just to return zero which is quite magical actually and then you can go a little bit crazy right here you have an example while all this code gets reduced to echo 1 return 4 and that's all PHP will execute and the end result of all this is that if you write really really crappy code PHP 7/2 and PHP 7 3 even more so it's going to run it really really fast if you run decent code you're not gonna see as much of a speed a speed-up from PHP 73 and 72 but it's been sort of PHP sting forever PHP runs crappy code really really well it runs it fast and it works and that's why PHP has become so popular because you try something and it just works and heck is even fast very few other languages can say that it's not always great but it really helps people get started with it and it doesn't prevent people from writing better code in the future it's just that they don't have this huge pressure to write better code so you end up with some bad code and that's where static analysis comes in which was my next topic so I wrote this static analysis tool called fan you can find it at github.com slash fan very easy to install be a composer or you can install it directly just by cloning from github you can initialize the - dashing it creates a dot fan config dot PHP and you can run the vendor bin fan on your project and it checks all kinds of things if you have phpdoc type annotations in there it'll check they're correct check that all methods are defined everything you anything you call in any constants properties that you try to access in your code it's all defined and at the all right access level for you to call it checks type safety everywhere version compatibility checks for no ops unreachable code unused statements all kinds of things you can also write plugins that extend the stagnant analyzer to check for whatever you want and there's a bunch of included plugins I'm gonna demo a few of them so here I have a bit of PHP code and I'm actually showing the vim integration because I'm a big guy bi guy forever if I were to change this constructor to say this returns an integer and I save the file it's complaining wait a second constructors can't declare a return type because it makes no sense nothing's gonna catch this return value so fan can catch stuff like that loops oh my undo other things say you miss the bracket on the count I mean this is syntactically ballot in not what you meant to do right if I try to say that it gives you all kinds of errors saying wait a second non bool is evaluated in if which is one of the user plugins I have enabled right now but you also have this array to in comparison where you're comparing an array to an integer which is valid but it's probably not what you meant to do so here a fan can come in and really help out with silly things it also lets you have array shapes in the sense that you can say this property R is an array with the key is always an integer and the value is always a string and if at some point you decide to assign an integer into this array you'll see wait a second you're assigning an integer but properties see ARR is defined to be an array of int string type right so here it catches the fact that you're putting in a value that you said shouldn't be possible because you said it should only be int with string values it also does even more if you mess up a red X it actually can go and look at your records and say hey this is not a valid rekhs and this is before running your code right this is just a static analyzer going through and also even printf strings and stuff so here we're passing a string to a printf and you can figure out let's say wait a second you're passing in a string but you're using percent d in your printf string which actually means integer so that's probably not gonna do what you want it to do and also one of the user plugins you can do things like tell it well I'm not going to allow something like this oops personally I love dollar dollar variables but I know many people don't and here you can add the plug-in there's a dollar dollar plugin for fan we can make that so other day company why Paul don't do dollar dollar stuff in our code base at this company and let's see we run fan on what people can run it individually on their own machines but we also run it as part of the test suite so if you're going to push something to production it has to pass all our fan checks including our plug-in things and it catches a ton of silly mistakes before it hits production because unless you have 100% code coverage and your unit tests which nobody does and that's a waste of time trying to get to 1% you're going to need a static analyzer like this to help catch things all right I am completely out of time thank you very much and there are references here to everything I talked about [Applause] [Music]
Info
Channel: Coding Tech
Views: 200,654
Rating: 4.9202814 out of 5
Keywords: php, php7, software development, javascript, web development, wordpress
Id: rKXFgWP-2xQ
Channel Id: undefined
Length: 30min 57sec (1857 seconds)
Published: Fri May 25 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.