25 Years of PHP (by the Creator of PHP)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Fascinating to see how far an accidental project has come. I am unreasonably excited for indented heredoc.

👍︎︎ 17 👤︎︎ u/d0gbread 📅︎︎ Jul 11 2019 🗫︎ replies

I usually can't sit through long videos like this, but this was pretty entertaining and interesting.

"I always thought 6 months was how much PHP had left before it was replaced" :D

👍︎︎ 11 👤︎︎ u/GTCrais 📅︎︎ Jul 11 2019 🗫︎ replies

Why did Rasmus say ColdFusion wasn't the way to solve the web problem?

Form what I recall coldFusion was a BETTER PHP in the early days. IT had more Database bindings, easier to use tags, more functionality, the only real issue was that it was proprietary and cost money to license a CFM server.. Eventually free and open source PHP caught up..

👍︎︎ 5 👤︎︎ u/abrandis 📅︎︎ Jul 11 2019 🗫︎ replies

Oh, dear, I had so much fun with C++, Erlang, Scala, Haskell, Python and even Agda. But each day I like PHP more and more!

👍︎︎ 6 👤︎︎ u/dima_mendeleev 📅︎︎ Jul 11 2019 🗫︎ replies

Wow, I didn't knew there were actual (real) people who live in Greenland!

👍︎︎ 13 👤︎︎ u/el_programmador 📅︎︎ Jul 11 2019 🗫︎ replies

loved this video!

👍︎︎ 3 👤︎︎ u/marcusneumann92 📅︎︎ Jul 11 2019 🗫︎ replies

loved the video, especially because he goes into the new stuff too.

It's great to see how this language was mostly developed "by accident" and just kinda "happened" because nothing better came around for a long long time hah. Great story :)

I didn't realize the new typed properties will affect performance. I guess it'll be case by case so we'll find out how much.

👍︎︎ 2 👤︎︎ u/Ravavyr 📅︎︎ Jul 11 2019 🗫︎ replies

Higher quality original version appears to be this one: https://vimeo.com/channels/phpday/345936757

👍︎︎ 2 👤︎︎ u/omerida 📅︎︎ Jul 11 2019 🗫︎ replies

I never realized what a big deal the foreign function interface is. I thought it was meant for optimization or something, but if in the future we'll really be able to essentially install extensions via composer, that would be insane.

👍︎︎ 1 👤︎︎ u/Pesthuf 📅︎︎ Jul 12 2019 🗫︎ replies
Captions
that's where I'm from every now and then people ask me oh that's hard to see down there isn't it but I am from northern Greenland place called Curtis walk on the island of disco in the middle of disco Bay and born in the 60s I'm old as the keynote yesterday was saying we're all getting older I'm sorry leading the pack here I think almost there might be one or two older in the room but not many this is me still me family my parents on the dogsled it's a pretty crazy place to grow up this was the house that's the view in the summer time of the house and the backyard and the front yard I guess me hacking more hacking getting older still living in northern Greenland very very crazy place so this is before the 25 years starts but there's a sort of the getting there then in the 80s started hacking on actual computers although not sure you can call this a real computer and had a cell it had 1024 bytes of memory 1k native that big box on the back was a 16 K memory expansion crazy completely crazy compared to what my son has today to play with and hack on it's nuts like 20 modems that know them I mean this was me growing up this was my internet if you will there was nothing 80s or 90s we started getting closer with gopher when I was in the university I used gopher reading research papers at the bottom of the research papers you could scroll down with the cursor keys and click on links to other research papers that was as close to the web as I ever saw in university after I graduated University in October 1994 mosaic was released first graphical web browser and here the 25 year counter starts for me this changed everything right and not just for me for everybody and it wasn't just me that I could see that this would change things everybody around at the time playing with this stuff and having had uucp addresses and playing with Usenet and bulletin boards it was very easy to see that this was going to change the world so I started hacking on this stuff right away the web looked like this CGI pins written in C not a pretty sight and not something you'd want to maintain having HTML inside your C programs was not a nice thing to have lots of people starting using CGI p.m. Perl module for writing CGI programs and I didn't like this any better still programming your HTML in some other language which to me made it impossible to separate the business logic from the templating and the look and feel the layout of the page and I wanted those two separate which people especially saw that the the non PHP types tend to chuckle at because PHP is quite well known for mushing it all together that wasn't the original intent my intent was to have very very simple templating so that's the same example written in Perl and then see here would look look like this in the PHP template in system right it looks like HTML with just a few tags here and there we need the dynamic content from the form submit my grand scheme was to write a capi for the web so abstract away all the web specific things that you needed to know to get your business logic up online and the idea was that you would create these template tags you would add your tags to the templating system by writing small C functions so here's an example of like a cosine function that you might want to add they were stack based so the tag would pass with the the templating system would read this find this tag and CA okay this is tag name Coast's there's an argument the input it would pop thee or push the input argument onto the stack in the C code we pop off any arguments from the stack call whatever function and then push the result back onto the stack and that's how it'll work and you wouldn't need to know anything about how to parse cookies of HTTP requests get method variables post variables all that stuff was taken care of for you all you had to do was write so there's a core piece of your business logic and C and then expose that business logic to your templating system much like you do and things like smarty and things where you assign values to variables and expose that to a templates except you are assigning it from C and this is how I like to solve the web problem back then and I did figure other people might like to solve it this way too I was completely wrong nobody wanted to write C code and it was a bit distressing to me at the time actually I was trying to convince people people would email me and they would say this PHP thing is cool you have all these tags built in and I included a whole bunch of demo applications and tags and things and they would say well we need and we also need a tag that does this we can't figure how to do this I would stroke this so easy this is the C code to do that and they would say thank you and then now we need this one we can't figure out how to do this and I would do it and there would they would trick me into building their site basically and it just kept going and going and then people started asking for more and more logic in the templating system so recursion things like that that I didn't really see any need for in a templating system and I wasn't all that good at writing a language parser I mean the templating system was pretty simple it was just a state machine you're either inside the template tag or you weren't and it was very very simple in the beginning you couldn't do math you couldn't do anything in the template system but people starting asking for stuff like that like just math itself it's really really hard if you're programming it right because I always parsing it I was wasn't using yak or Lacs or anything I was just parsing it left to right and you get one plus two times three you can't do that left to right you get the wrong answer okay you have to do the multiplication before the addition and the whole thing just kind of gets really complicated really really quickly when you're just trying to build a state machine in your head that parses an entire language but it was very obvious that people preferred just working in the template existence and I shifted the focus completely away from necessarily I mean I got the language working I read a book on yak on yak and Lex and kind of figured out how to build a somewhat usable parser where it could offload like the math handling yak and Lex could take care of all that for me for the most part so I got a parser that kind of saw that worked okay and then I worked a lot on the ecosystem in the early days making sure that all the different pieces could talk to each other because really what you need you need a robust system where you can talk to all the different things that you need to talk to you don't necessarily need a beautiful language to program in you can have them best language in the world and if it doesn't talk to your Oracle database where all your data is there's absolutely no point right and that's really what I focused on I focused on making sure that the four pieces that are critical so a pipe web application would work well together so an operating system a web server scripting language and some kind of back-end datastore a shared datastore and it really wasn't an accident lamp came around and it wasn't just me I mean I I got the ball rolling but there were lots of people that helped out in getting the whole ecosystem running well and some of the things over the years like initially mod PHP was the big one embedding PHP into Apache was huge because other languages specially back then were faster and better but they all ran as CG is Perl was way faster than early PHP but not once you embed PHP into Apache by the time use fork and exec a Perl process and wait for the interpreter to fire up on every single request PHP was already done the fact that by the time Perl got started it was really fast didn't help them because their overhead was so high being CGI it took them a couple of years but the mod Perl eventually came around they figured out hey we need to do this - we need to embed Perl into Apache and they completely messed it up because they made it way too powerful I only hooked the content generation hook in Apache which is when the patch Eve has figured out where's the document root and where's the script and everything then it would call PHP and say okay for this particular file the handler is PHP run PHP and send the content back with mod Perl you could hook all the different request hooks in Apache including the path translation hook which is the hook that says for this particular request this is the document root that meant that if you are on the Virtual host on an Apache server and you had mala parallax's you could steal the request from every the virtual host if he wanted to simply by hooking the path translate hook and pointing everything to your document route and that meant that ISPs could not offer mod Perl as a shared virtual host alongside other clients in a single Apache instance so if you came to a nice piece that I would like mod Perl they would say okay that'll be six hundred dollars a month because back then we also didn't have VMs contained there was anything like that so you had to have a separate physical bare metal box for more mod Perl whereas on PHP you could put three thousand customers on one machine versus one mod Perl customer so it died ISPs I mean ISPs would offer it but nobody would want to pay a hundred times more for Perl verses PHP I also pushed really hard for a long time in the beginning for the whole concept of a shared nothing perfect sandbox model where we fire everything up and take tear everything down after request no state is stored in PHP server side if there is any sort of state on a per machine basis that's something that you did as application developers and also multi-threading I've always been firmly against any sort of multi-threading because it just gets too complicated we as humans are not smart enough to write complex multi thread safe code and when you link in dozens and dozens and dozens of third-party libraries and expect them all to be thread safe it's just no way if the scope is limited enough you can write thread safe code but for something like a general purpose glue language like PHP there's just absolutely no way you can get that right and also if you have multiple threads if one screws up which it will it will take down all the other concurrent threads even today 25 years later at Etsy where I work we run PHP and every now and then there's a segfault it's rare maybe one or two a week and I have no idea why they happen but I don't really care it's like once a one every three billion requests will cause a segfault and the pachi just says ok we'll start another child who cares we move on that makes it robust if we're in a multi-threaded server and one child dies or that causes any sort of memory corruption that entire group of concurrent connections are gonna die as well which is not a good thing h/h VM stepped into that one as well because they they do multi-threaded concurrent requests model are the things I worked on in the sort of the ecosystem bucket was the SQL lipid clause because I was using a database called M SQL this was pre MySQL 1990 late 94 the 95 or so I was using mini SQL super smart guy named David Hughes in Australia had written this tiny little database that was perfect for the web it's SQL was quite limited it didn't have I don't think it even have joins back in the early days but just as a very simple datastore that was perfect for simple web SQL queries it was awesome but it had no way of limiting the number of results you got back from a query so if you made the fatal mistake of doing a select star on a table that had a couple hundred thousand rows in it and because we didn't have any sort of 10-gig network cards back then you were waiting for awhile for that entire result set to come across and if you only need it the first one it really sucked waiting for 400,000 rows and then just showing the first one right so it was super obvious to add some kind of limiter to these SQL queries so I arbitrarily named it limit and patched it in got it accepted upstream in the thing and that has caused limit now to propagate through many many databases I find kind of interesting and it's not standard at all there's an ANSI SQL standard there's no sign of limit in the in the standard still also on the isp side like maximum execution time memory limit and safe mode helped ISPs feel a little bit better about offering PHP because they could say well even if you write a while true PHP script that kind of hurts the server but because there's maximum execution time with just CPU time based after that menu CPU seconds it'll just get killed off so it was somewhat okay for an isp to put thousands of PHP users on the same server still not ideal but in the early days of the web it was very sort of Wild West you kind of hoped for the best that with just about everything you were doing some of the things over the years that people keep asking me about I case-insensitive function names it doesn't make a whole lot of sense today but for all of these decisions you have to take the context in mind this is from 25 years ago this one when the web first started there was a huge religious battle on whether HTML tags should be upper case lower case or even mixed case because my template existing wanted to fit in this world and I didn't want to take sides I wanted everybody no matter what their religion was to be able to use PHP templates these tags which were essentially just function names in the early days there was no point making them case sensitive because then people would complain that they couldn't fit into their style that they were used to in their HTML and that has just stuck now when HTML when everybody did finally sort of get to lowercase I probably should have switched it but I remember thinking about doing it 97 maybe 96 and I remember thinking this will affect hundreds of sites as a man I can't inconvenience hundreds of sites looking back now like I should have inconvenienced a couple of hundred sites at the time but I had no idea I had absolutely no idea I figured at every sort of at every point along the way I figured there was about six months of life left in PHP because that's about the amount of time I thought it would take for somebody to write something real that could replace it and that also would work for me and I kept waiting for something to come along that I could use that would work for me and nothing did idiots came out with stuff like ColdFusion and another thing is I looked at god what the hell this isn't how you solve the web problem and then and confusion became popular even like wow this is this is just a weird world we're in I guess I'm stuck with this naming inconsistencies there aren't actually any the naming in PHP is perfectly consistent just not the way you expect dollar signs people have complained a bit I even have people saying why dollar this is very American centric come on Global's this is actually one of the better decisions I think very few languages do it this I'm straight any languages actually hand the Global's the way PHP does this came out of a huge debugging debacle I had pre PHP I was at a company called Nortel in Toronto as a co-op student and I was given the task of tracking down a really complicated bug that would take down this automatic call distribution system every couple of months this was a system that would distribute calls geographically across Canada for for the main customers Air Canada so if people called in after-hours on the East Coast the calls would get routed to support people Manning the phones on the West Coast because it was three hours earlier out there so they had these queues you sit there on hold waiting in these call queues and every couple of months the system would just drop every call out of the queue which Air Canada was quite unhappy about understandably but nobody could figure out why every couple of months this would happen they tried finding it for years and it just they didn't see it so that was my task as a co-op student and it was kind of a joke there is a fix this like good luck they didn't think I would get anywhere they figured I would learn the system from trying to track it down but anyway I printed out the source code on this huge wide the wide dot matrix pages we had back then taped it to the walls of all the hallways in northern telecom there and at after-hours I always put that in the floor and I would have these highlighters different colored highlighters and I'll be crawling around on the floor and on the walls and a chair I could stand on to reach the higher things and I would just sort of manually debug everything and try to track down the flow of this thing and it was nasty and in the end after three and a half months it turned out to be a global variable collision two separate pieces of the code and completely unrelated had the same name for a variable and it was global changed in one place at exactly the wrong time would cause this other code to go crazy and the C compiler at the time had no way of informing us that that was happening and it was just crazy and then I started adding variables and scope to PHP I remembered that there's no way that in PHP I'm gonna be spending three and a half months tracking down something like this that's so in PHP if you were gonna step on a global you have to damn well declare the fact inside the method or a function that you're going to step on the global so you have the dollar Global's array with a huge capital letters this is a global or have to declare this out the function global right so you can't accidentally step on the global in PHP let's change a little bit now with the Auto capturing of the arrow functions that's coming which worries me a little bit the first time a bug appears because of Auto capturing and arrow functions I'm gonna go kick Nikita register Global's without register Global's we wouldn't be here honestly register Global's enabled users who had no idea how the web worked to build dynamic pages to put up an HTML form name age address as the field names and then add tags that just said echo name or if age is greater than 19 without thinking about anything the fact that field names became variable names in PHP was the killer feature in the early days of the web where people didn't even have to think about how it worked it just worked also context there was no Java Script you couldn't do cross side scripting you couldn't do any of the things that in later years you could do with register Global's turned on magic quotes magic quotes was me being lazy I admit that one this was not a good solution but it took me a while to discover that I should probably be careful about letting user data into SQL queries I had already written this big system for the University of Toronto and I had dozens of PHP files and say ah man I have to go through and then filter all my SQL stuff and all my input data forget it I'll just do it once and I'll turn on the flag turn on magic quotes and have PHP do it for me because I was too lazy to edit my my files so yeah that's I don't have a good excuse for that one other than laziness but it also comes back to my six-month thing I always thought I was six months away from the end of life of PHP right this was a tool primarily for me that other people started using but whatever I mean once that new thing came along that fixes all the problems we would all switch to that I could never have imagined I'd still be talking about this thing 25 years later so on the consistency thing on saying that hey it's perfectly consistent do you realize that every single array function is needle haystack and every single string function is haystack Neil perfect consistency right so the consistency in PHP is vertical not horizontal because of the way it grew organically right so different people wrote the various extensions so when you're talking to the Oracle database using OCI 8 the functions that talk to Oracle from PHP are almost a one-to-one mapping of the underlying seed library functions or the API functions provided by Oracle same with the MySQL functions and the other database functions and they all across PHP even the string functions are direct one-to-one mapping of Lib C functions right so the argument order and the names come from the underlying libraries that were wrapping where PHP is a very thin wrapper basically just exposing these C libraries directly to you getting horizontal consistency across a diverse set of underlying libraries would have taken a hell a lot of planning and organizing and sort of predicting the future the web was moving so fast there was just no way that that would happen we needed a tool right here and now the web was growing like that and if I had sat around worrying about horizontal consistency we also wouldn't be here today all right a little bit more current stuff 73 hopefully everyone in this room have at least looked at 73 hopefully you're in the middle of migrating everything to 73 does anyone in here still running php5 you're killing me man [Laughter] I was expecting maybe one or two hands to go up but the whole back of the room lit up okay anyway so in seven three also in seven zero for you folks in 71 and 72 there are some nice cool new features but in 73 we've made hair Doc's look a little nicer because the ending tag doesn't have to be on in the left column so whatever that's indented by is the same indentation you'll see in the output so if it's in four spaces then four spaces will be removed from the content continuing switch continue is probably wrong if it's a continue inside the switch that's inside a loop people might expect that that continue will continue the loop it doesn't it acts just like a break when you do a continue in the switch so PHP 7/3 has a warning that says this probably bleeeh continued to it either should be a break or continue to so if you see these and the and you did mean that break here then just change it to a damn break list references both the long since X and the short subtext now support references trailing comma without in function calls now we had kind of forgotten that and there in 72 we added trailing commas support to most things but we didn't add it to this one it's also a new monotonic timer function if you're doing any sort of timing in your PHP scripts currently 373 you're going to be relying probably on micro time to do this timing which is pretty broken because micro time relies on the system clock if you have ntpd running ntpd can speed up slow down stop even make your clock go backwards by actually I don't think anything can could make it go backwards but could make it stop for a little while your sister an administrator can arbitrarily change the system clock and make it go backwards so if you're timing something and your end time is before your start time things get weird right and all just the fact that ntpd can slow down the clock a little bit just to sync it with the NCPD time also means that your timing is not gonna be right the monotonic timer function will always click forward one second per second and this is really what you should be using to time things there's a cool new fpm get status function so you can write very pretty dashboards kind of like the Apache scoreboard where you can see what each request is doing you know in Apache you can do like a status / status and get the scoreboard you can now write something similar if you're running F p.m. it's countable one of the big changes in pH P 7 - that makes upgrading really really difficult sometimes is that count complains if it's called on things that aren't countable so if it's not an array or not an object that implements the countable interface it complains we saw that a lot of people were calling his array or instance of countable to try to figure out if foo is countable now you're cold you really should know what type of variably you might be dealing with here but that's not really the PHP way in PHP you never know what the hell is in a variable because you've written code well you have methods that can return six different types based on all kinds of different things and so you don't know so you have to check can I actually count this so there's a new accountable function in PHP 73 that just reduces this boilerplate to something a little less nasty also to avoid the reset usage like people will call reset to get the first key of an associative array and that also moves the array pointer which means that you can't call it on something that doesn't have storage you've probably tried to do like a reset on a function call that returns an array and you end up getting an error right with a Reiki first nor a key last you can now get the first and last keys very quickly without any side effects there's a whole bunch of cool DC and sccp optimizations in in 73 which I'll talk about in a bit some other changes the big one here from a sort of a stuff that will break your code is the pcre to upgrade it should be rare the main difference there are actually quite a few differences between 1 and 2 but in pcre - the main one that you will likely hit are invalid character classes you know how you in character class you have sort of in square brackets a - Zed for example and that means all the letters from a does that if you have a - backslash s so a - whitespace what does that mean who knows and in peace Yuri one says we don't know what this is so that - in the middle must mean a literal so this is a a - and white space in pcre 1 which makes some sense right because it's in an invalid character class so it's not actually going to be a class it's not gonna be arranged in pcre - they've said while you try to build a range this is an invalid range this is an error and it won't compile the regular expression for you and you'll see a big warning in your air log if you ever look at your error log which I don't think many people do you'll see a big warning unable to compile regular expression and your code will break the count thing in 72 is just noise in the error log it actually still it's the same value so it doesn't break your application this one breaks your application because it won't compile the records and that wreckage will not do anything right so when you do the upgrade 273 make sure you scan your error log and your unit tests and everything for invalid or errors from PC are you saying it couldn't compile your regular expression and most of the time all you have to do is go in and add a back slash in front of that - to make it a literal because that's how it worked before in PCR 81 it was treated as a literal - if you had a back slash to it it'll be valid in both PC R u 1 and PC or you - and it'll do the same thing read the migration document if you have extensions read the upgrading internals document that helps you figure out what you need to fix in your extensions for the folks still on PHP 5 you know a lot of these to read right so there's migration 7 0 71 72 73 if you wait a few more months you'll have another one to read 74 it gets harder and harder the longer you wait all right 73 Dimitri in Saint Petersburg has been having lots of fun with DCE escape analysis and sccp sparse conditional constant propagation sounds very complicated but it's actually not complicated at all it's kind of fun you can dump up codes after the optimization pass with a tricky little set of settings like this our cache optimization level - once to turn on all the bits and set it to hex to 20,000 it'll spit out the opcodes after the optimization run and you will see for a simple script like this that just has a function and because of the Global's and PHP this is a local variable there can be absolutely no side effect from setting a equals one and since we don't use dollar a in anywhere and just return zero this is useless this assignment serves no purpose whatsoever in PHP 71 and earlier we still create the opcodes for it so we have the assign opcode that assigns one $2 a and we return 0 7 2 & 7 3 the optimizer sees this as being redundant and doesn't even generate the opcodes which means they don't get cash to not cash and that's really where you're executing from so essentially it's just deleting that line of code and that never gets run which also means your code runs slightly faster because there's one less opcode to step through more complicated things so here are the CV lines it's basically just saying where the inputs the input arguments are stored these aren't like executable our codes is just saying these are stored in these four places then seven one will happily concatenate do the concatenation s1 and s2 s3 and s4 and then they concatenate there's result together here t6 and t7 get concatenated together so now we have the final dollar X then we overwrite dollar X probably right t5 to X then we overwrite it with 0 and we return X 72 and 73 see through all this mess and see that hey all this concatenation gets overwritten in the very next line plus X is always 0 so we don't even need X right so it replaces all this mess just with the return 0 opcode no come Katz no creating a variable X nothing that stuff never happened and try the trick it stuff like this it figures it out still so here we're only incrementing a we're also setting B so that result but we're since we don't use it the B part gets eliminated in 7 3 it has gotten smarter with array stuff so in 7 - it couldn't figure out arrays like this more and also objects so in 7 3 it looks up one level to see off to test for side effects so if you instantiate an object like this if there's no whole destructor and no constructor then there was absolutely no side effect possible from a instantiating dollar a here and even setting a property there's no setter up here either so the opcodes just removes everything and it just returns X if in that same example we added the structure now you can see that it did not remove those off codes anymore because now there could possibly be a side effect once dollar a fall saw the scope and this structure is called there could be a side effect there even though in this case the structure is empty it doesn't actually check because that would be another level to check it doesn't actually check if the destructors MJ just checks if it's there also it's smart about arrays now in 73 so here if you kind of follow this it doesn't matter if X is true or false e will only ever returning the first element of the array so all this stuff gets replaced with just to return 0 because the optimizer sees that no matter what the input is the output is always 0 so everything in between can go away since there are no side effects and you can delete all that code and you can go kind of crazy you have code like this right the optimizer tells us that all this does is echo one return for you can totally try to make your way through it and validate the fact that it will always only echo one return for that's a lot of op codes that have been eliminated so like I told and most people don't talk too much about how much faster your code is under PHP 73 because if it's drastically faster under 73 you've written code like this right it should be 5% maybe 10% faster if you stretch it over like 7 1 7 2 it should not be like 30 40 % faster if it's 30 40 % faster then it's the optimizer eliminating all your code basically deleting your code and saying you're an idiot all this code doesn't need to be here alright so this is the real performance gain you can expect from 73 the last bar here right so going all the way back to 5/3 this is in requests per second 154 requests per second for the front page of WordPress for 98 versus 520 today for it and latency has also been dropping nice the hundred and 40 milliseconds using PHP 5/3 down to 38 now no seconds on my test box so the actual absolute numbers don't matter but the the relation does matter right things have gotten faster every single version we get a little bit faster and memory has shrunk quite a bit running on 5 3 we need 140 Meg's today we need 15 makes to serve up WordPress version support this is where we are if you're running anything other than PHP 72 and 73 you're behind and you need to upgrade if you're still running 7-0 do you realize PHP 7 was released in 2015 an Internet on the web that's old it's old code PHP 7-0 is no longer supported in any way whatsoever not even security fixes are being done so if you're still there and the for the folks still running PHP 5 it's just irresponsible honestly she'll be running code that old on anything that might be important I mean if it's if it's your blog or something fine no problem right but if it's something that's dealing with customer data or anything that is actually sensitive you can't be running code that's 10 plus years old you can't do it all right stack analysis one of my side projects that I started and hand it off to someone smarter than me which is sort of my pattern I start things and I get them going I get in just to the point where they're useful enough for someone else to continue it as opposed to completely starting their own thing easy-to-install Composer require the fan fan very simple config file if you have a standard sort of composer set up with a source directory in the vendor directory you can tell it this is my source directory and my vendor directory scan it but don't report errors for that one so this is the exclude analysis directory list so it'll still be part of those other the map you could because you need all the dependencies you need all the types from those because you're calling into them but you don't want to hear about any errors in other people's code and then run vendor bin fan if you've never done it before you're gonna get hundreds if not thousands of errors reported about your code you can add some filters and say I don't want to know about this type of error and there's a whole bunch of different filters available checks a ton of things these days this is just a very small list of things that'll check that's a quick example I have a class like this with a function that takes three arguments the first one takes either a string or an integer called Union here the next one takes an array and in the native type in PHP you can just say it's an array with fan you can give it a more specific type you can say this is an integer array and fan will check that it's never passed something that's not an integer in that array and then the last one that's a shaped array and that's actually saying this array must have a key name mode with the value that's a string and the key name max with the value that's an integer I forget something that doesn't match this definition of the function fan will complain so here these first three calls were okay we have string integer array and a shape the Ray that matches this time we have an integer which is fine as well because this is either string or int and this one is fine what did I even change here doesn't matter then this one is not fine the first argument is an array right and that's not part of that Union so fan complains saying that the argument one is an array but the function takes integer or string another example here here are the shaped array is missing the mode element so it complains about that so these are some of the things that you can expect to see running fan another tool much newer than fan fan is 3 years old now I think 4 years old maybe lower head profiling is a cool new thing that we've worked on that Etsy guy named Adam super smart guy wrote this thing it's a little bit like RP spy I think there's a PI spy as well you run it like this you can attach it to any PHP process whether it be a PHP fpm whether it is httpd with mod PHP so PHP is running inside HTTP B does matter or just a standalone PHP process and the sampling frequency by default is 99 milliseconds I think if you don't specify it 99 not 100 because if you set it to exactly a hundred there can be some timing issues where you happen to exactly miss something because things tend to happen in hundreds of milliseconds as opposed to every 99 milliseconds so by offsetting it slightly you're more likely to not run into any sort but you can also change it yourself in this case I've said it to a lot of nanoseconds that's 200 milliseconds and I'm checking a script that's just sleeping for one second so every 200 milliseconds I'm asking PHP what are you doing what are you doing what are you doing what are you doing what do you think and it comes back every time with a little back trace telling me I'm in I'm sleeping and I was called from Maine right because this runs for one second then we check every 200 milliseconds we get five answers and then we get a no such process at the end because PHP has stopped here is an example of attaching to a PHP fpm process that's currently serving WordPress and you can see that the whether you doing response is a lot more complicated now the stack trace is much deeper you can also get the memory usage from each frame if you pass minus M and here if anybody wants a project to contribute to it'd be great to have some support for per for call grind or some other way of visualizing the memory here there would be a nice one too to add support for it sits on the to-do list just nobody's gotten to that part yet we have the numbers the hard part has been done we're getting the numbers out of every stack frame but we need to visualize it somehow for the straight what are you doing how much time are you spending in places we have output we have a flame graph that you can generate there are some scripts that come with PHP spy one is the stack collapse the other is flame graph which a Perl script of all things just kind of cool and what you get out of this is a flame graph that looks like this so this is me running fan sorry running PHP spy on fan so if i zoom into some of this I can see like here and analyze and get updated context calls into this other thing which visit statement list which calls into analyze and get updated context again and op the tree we can go we can follow it all the way up we use this thing at Etsy at ton we have a gear man pool of servers that handle gear man jobs some of these are quite long-running we also have servers doing cron jobs and again some of these run for quite a while and sometimes they run a lot longer than we think they should and it's hard to know what the heck they're doing because we try it I like on our development servers and it never runs for more than six minutes or something and then in production this thing has been running for 40 minutes what's it doing right we can't replicate it but with PHP spy we can hop on the production server attached to the running process without slowing it down and see what it's doing where is it spending its time on PHP spies in magic because you don't have to compile PHP in any sort of special way you don't have to have debug symbols you don't have to have anything you can have a completely stripped optimized GCC - o3 compiled binary and it'll still give you this output and it does it by simply looking at the kernel memory you have to run to this root which is I guess a bit of a problem for some but it's because it needs to look at the kernel basically it knows the offsets for the different versions of PHP so it knows where the eg Global's live for example the executed Global's live in memory for PHP 73 right that's another certain offset and it knows where all these places are so it's just looking at memory and seeing what's changing it also has an option to spy on them variable so you can track you can set every ninety nine milliseconds tell me the value of this variable and you can track how that's changing over time so so there's a lot of front-end stuff that could be added to this to make it even cooler Adam has mostly been focusing on the back-end part he also hates public speaking so if you want a project where you can have pretty much a guaranteed accepted conference talk for come contribute to PHP spy add the cool front-end support for some of this stuff and submit the talk and I guarantee you it will be accepted because it's really cool and Adams not going to mind he would love someone else just talk about PHP spy for you for us all right Pete's b7 for coming out leave those here type properties yeah if you don't care about performance you can find but I mean hopefully we'll come up with ways of counteracting the performance hit that this is going to take there is some obviously this is also why we're not going to do it for standard variables because every single time you modify one of these we have to add a type check so think of a loop in the reader while I plus wild dollar I plus plus write this thing every time through the loop we ratifying the variable for properties that's less of a problem presumably you're not doing while dollar this I I plus plus right hopefully not people typically don't make iterators property over their classes right so you tend to write less to them which is why the performance hit on this put on properties isn't as big as it would be typing regular variables arrow functions recently accepted these two are similar or identical so you can see why is auto captured here from the other scope you can have nested there are functions you can also put types in if you wanted to you can add a type here you can put colon return type as well on it pretty simple serialization has always been an issue in PHP there are various problems with the wakeup and sleep and wake up things magic methods sterilize and unsterilized gives you a way of controlling exactly how your class is going to be serialized and when it uncie realizes how it's going to answer allies instead of relying on some of the weird side effects that you end up with in the current mechanism it's a new null coalescing assignment operator coming so these two are equivalent weak references PHP is reference counted which means when a variable goes out of scope there are no more references to that particular piece of memory it gets freed in the sense that it's available for for reuse within PHP if you have something like a cash system or anything where you want to you want to avoid stopping something from being collected or being referenced counted if you have a weak reference it doesn't count as a reference so they say a equals something that comes back from your database for example and you in the cache it and you said B equals the reference to this and now you have a reference count of two then you might also have a cache reference to it now if both a and B go our the scope then this thing should be deleted freed but if the cache is still referencing it the cache will stop it from returning the memory for the system the cache should then be rewritten to get a weak reference instead then it doesn't count so it's only the two main references that count and once the two main references go away its reference counted and it's freed and the weak reference dies now the cool new feature is our cache pre loading it basically loads the use of space code that start up and then any code you have any classes any functions it's as if they were internal for the rest of the life of of that PHP instance that makes it harder to change that code obviously because if you need to make changes deploy a new version then you can't just have PHP stat it and recompile it because it's only looking at this stuff on startup or you could force you'd have to do some more complicated things to forcibly compile its inspired by Java hotspot VM and it works like this so if say you have code that just has a class a echoes out a in the constructor you probably have an autoloader and when you do a new a the other though the triggers loads in that PHP file a dot PHP and the class is run constructor runs we get a in the preloaded world if in your i and i you have app cache preload point it to a script in this case preload PHP in that PHP script all you have to do is up cache compiled file whatever you want to preload by whatever logic you want in my case I wrote a little preload function that I can pass the file names to that I want to preload and IAP cache compiled file those all names so in this case when I run that same script PHP this script here with the auto loader you can see that when I run it it doesn't say that the auto loader was triggered it just outputs a because on startup it preloads a and that class is registered this might seem like a lot of stuff that doesn't necessarily give you a whole lot of benefit it helps you a little bit because even though app cache compiles and caches the opcodes there still is a little bit more work to do to bring those up codes into scope and to create the class in this particular request for example you can have five classes all with the same name write in different PHP files and depending on whatever context you're loading one file over another you pick the right class out of op cache and create that for that request in the preloaded world you can only have one class with that name you can't preload two classes with the same name that just wouldn't work you would get a redefinition error but they're also kind of illustrates that there is a little bit extra work involved if you don't preload something so there's slightly faster but where it really becomes interesting is when combined with FFI foreign function interface lets you create this FFI object directly from an underlying c library in this case this example is really simple this is just loading in Lib C and defining this is base we think of this as a header file right so this is a header file you know the end that just has the prototype for the printf function and we're telling it grab this from Lib C dot so6 now off of this FF I object you created you can now call anything that were defined any prototypes that were in that header file you now have access to directly and you can call directly into the C printf are completely useless because PHP already has a printf function that does exactly that basically to test it out I went and grabbed a library called gif Inc alpha github it's a very simple little library the header file looked like this the top two lines are something I added you can ignore those but this is exactly the header files to come with the library the hello file and it just defines three functions nuke if GE Nuka of GE add frame and close gift right so this is a little library that creates animated gifts it has this somewhat complicated structure for the gift Heather number of frames color depth things like that to load that in because I added these two I set a scope and I told it which shared library this is in that's the only two things I added to the header file otherwise I just pasted it directly and I can just load that header file now and it does everything and it compiles the code and creates this FFI object and now I can just play with the FFI object you still need to know a little bit of C you need to understand for example that this color argument to new gif the fourth argument to new gif if we look at it here you can see you get the filename width and the height these are just long so that's easy enough but this one here you end eight pointer Oh what is that right if you're in the PHP world now you're looking at C pointers you kinda have to know what that means that this is actually an array of you ain't eight unsigned integers that you're passing in so in this space you have to create this array and you can say FF I knew you in Tate and I want 12 of them because these are the colors that I'm passing in and I pass in RGB values for these colors then I can call the function for these the simple Long's we can we look at the the thing we look at these go now wrong key you look at these and you have - no enough seed to know that this is just a PHP long will do here and PHP long we'll do here char pointer that's just a string just pass a string in this case again integer integer it's fine to just pass a PHP integer in here this one you have to create separately right great that separately do a bit of loops add a frame different colors every time through close the gif and the result is that which is kind of cool but pre-loading + FF I is super interesting because this step is deadly slow the FF I load you do not want to do this on the per request basis but if you preload this thing on server start up all your F of I blocks are going to get compiled and added directly in to PHP as if they were an extension I can see a whole bunch of our very thin extensions that just wrap see libraries I can see these being converted to pre loaded FF eyes that you can just compose or install directly because they're really just PHP scripts so they can be managed through composer and also all the data marshalling like all this other stuff is just PHP code right the amount of C that's in here is creating that header file and then a little bit of creating the types maybe that you need a C developer for all this other stuff people who only know PHP can happily maintain the other parts of the extension there's only so much that's actually needed for these the C part right and you need a C developer to get the base right but then from then on any little change to that extension can be done in PHP managed through composer it'll it'll increase or broaden the the users the amount of users that can help maintain extensions and I think it can kind of change the world for us we'll see all right I know I'm pretty much out of the time but one last little rain so these 25 years also included having a son 17 years ago me hacking on some PHP stuff gain on the ThinkPad Mac's were cool back then so I had a sticker I never really converted it to the whole Mac thing oh yeah little Karl being like three days old at that point I think two days old maybe a little bit later anyone in here remember Linux talk college school yes so Karl would run around he was really really good at finding the on/off switch on anything he would run from booth to booth at this big Linux tax conference and he would find the off switch and turn off these servers which didn't I mean he was a cute kid and he had his PHP shirt on so they couldn't get too upset at him but there were a few that were really grumbling because he would circle back and do it again and again now he's 17 he's driving playing video games in the car right it's a completely different world that we live in now and he has hair down to his elbows yeah very very different and it's making me feel rather old when my son comes and picks me up also over these 25 years I used to go to Australia every year we had some great hacker gatherings this is andrew tridgell famous for our sink and many other things lena stalls a bunch of other AHS hackers in here you can see this was before LCD panels or anything right this is this is old old school some other highlights for the 25 years this is me in India at the conference I don't have a suit like that these conference organizers thought that while there are speakers are so important they should be wearing suits so they Photoshop me into a suit and there are these huge posters all over the town of me in this suit looking very important I guess and I saw that I know what the hell this was another highlight this was in Sri Lanka anyone know who this might be sitting here you're cheating yes the arthur c clarke one of them so that you can't see that okay you have good eyes yes arthur c clarke lived in sri lanka for years and years and years he came to a PHP conference and said right in the front row asked questions completely engaged and it was super cool to teach PHP to arthur c clarke although the really cool thing about this particular conference was that this was in 2005 in december 2004 there was the huge indian ocean earthquake i don't know if you remember but there was a massive tsunami after that that slammed in sri lanka a lot of people died out of that came something called Sahana and the Sahana project is a disaster relief project and i talked to the folks there when I was there and talked through some of the things that they could do with PHP in Sahana and this is one of the things that makes me still contribute to PHP makes me still feel like it's worthwhile even doing some of the things when I get slammed with flames and blog posts online about all those all the bad decisions I've made over the years but then I go to Sri Lanka and I see something like this kid at the University and also a guy working for the government there got together and built a disaster relief in a box management type system where basically if relief comes in Plane full of diapers comes in someone on the ground will say we have diapers they're over in hangar number three whatever same for whatever else comes in so you can keep track of aid coming into the country you can also there's also people finder so this is a very simple front-end for the people finder and there's also a mobile app now where the rescue workers ask the person their name take them to shelter number three and the enter that into the mobile app and then you're online you check where's my grandmother put the name of your grandmother in and it'll tell you yes she's been found she's over there right and there are seven eight nine different modules like that and the the value is that this can be spun up in three minutes right this is just a package that you spin up super super quickly and it has been used now in the 50 plus disasters around the world knowing that PHP has literally probably saved someone's life makes all that online grief completely irrelevant this is a tool PHP is not important what you do with it is important if you save someone's life with something you've built that's awesome arguing about the color of the hammer used to build that thing it's just moronic and all these flames about the technologies and stuff we can't lose track of what we're doing here why we're programming we're programming to solve a problem and hopefully it's a problem that actually matters right it's a very nice quote from the second national secretary of defense of the Philippines who set that right directly targeted as Sahana because he saw what Sahana did for a big disaster in the Philippines so it was a much slight thing back then so work on things that matter to you please I see a lot of people that have left why there are a lot of people I don't see in this room and in the other conference rooms that I go to that were there 10 years ago but now they're middle managers they're not programming anymore they burned out they changed jobs and sometimes that that's just sort of the progression then they make sense for them and there are good managers there are also a lot of really crappy middle managers out there there were great programmers and they become crappy managers because they don't feel like they can keep up it's too much work to keep up with how fast technology is moving which is kind of code for that they've lost interest they're not more than they motivated enough to actually sit and read about things in the evenings they have a families now and it takes more time and I understand that I have a family but there's still this Drive there's this passion and motivation that makes me continue if you don't have that you will burn out and especially the younger folks in the room you love programming but will you still be programming when you're 50 60 70 maybe you don't want to that's fine perfectly fine but if you want to if you love what you're doing really look at what you're actually doing and don't worry that much about the tool if you switch tools fine it's it's what you build with it that's important I'm sure there are all kinds of geek arguments about paintbrushes what's the best paintbrush that painters might have internally doesn't matter what people remember are the actual paintings right who made well I was gonna say Michelangelo but that's he's a big PT guy right so but I mean who created mo built Mozart's piano if you're a music geek you probably know I mean maybe you know but who built the piano isn't as important as the actual music that was created with it right and that's what we're doing we're building things and things come out of this I think I am squarely in the middle of this chart I can code a little bit I'm not a very good coder I'm sort of a mediocre coder I don't particularly like programming I built PHP because it was too complicated the tools I had at the time just weren't up for the actual task I thought it took me too long and was too hard and too tedious so in order to program less I spent the next next 25 years programming something that would let me program lasts it made no sense but still it did allow me to build things along the way that actually affected people's lives and that still keeps me going and I'm very very thankful for the Y's there are a lot of Y's that have helped out on the PHP project over the years people just love to code doesn't really matter what they're coding they just sort of love the act of coding they love the journey they don't really care where they're going kind of like flying right I hate flying but I spend my life flying I fly a lot because I want to get to somewhere not because I just like sitting in this smelly little tube with a bunch of people all right and saving that there are lots of dreamers out there that have absolutely no basis in reality to know if they can build some of these dreams and that you need a little bit of grounding to figure out if this grand idea you have can actually work all right that's my rant and I know I'm over time sorry conference folks so slides are there a couple of links thank you [Applause]
Info
Channel: Coding Tech
Views: 171,940
Rating: 4.9350348 out of 5
Keywords: php, software development, php programming
Id: wCZ5TJCBWMg
Channel Id: undefined
Length: 71min 50sec (4310 seconds)
Published: Wed Jul 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.