Good morning, afternoon, and evening, and welcome to September's a 2018 nomad, PHP Europe meetup. Today's week we have a tremendous speaker which I'm really excited about with a educator and now it's going to be a special episode of nomad PHP, but it's also special because we're at the heart of Northeast PHP in Boston, Massachusetts. Served by a lot of great speakers, great PHP attendees, and of course, awesome sponsors like a red hat, IBM nomad. Of course we're not really a sponsorable. We're here RingCentral, next mole and a ton more.
I also remind you about the new subscriptions. So we're changing our subscription model with nomad PHP. What this means is instead of paying $20 per video or $25 to see the video after the fact, or $24 a month for a subscription, you know, are just gonna pay 1995 a month, 1295 per students, and you can get access to all of our previous meetings, access to, of course, our liabilities and a subscription of PHP architect magazine. We also wanna try and make the community far more inclusive. So we have a community blog. We'd love for you to share your knowledge, share your blog posts in interactive message, other members. The biggest thing we asked there is just remember to treat everybody with respect and to be courteous.
I also want to quickly thank our sponsors for it. This mean here we have [inaudible] are open sourcing mental illness. Osby is one of those great organizations out there that really puts the community first and really understands the way the developers think and the needs that we have as human beings. They do a tremendous job really raising awareness, but also helping to train companies to make sure that they're treating their developers mental health, just as important as our physical health and making sure that you know, their game, the resources they need to truly be successful. I also want to thank RingCentral developers. Of course we're using RingCentral means for the first time here, but RingCentral provides API as SDKs, widgets and bots for voice text SMS team messaging meetings. Facts and more I have a hard time to remember all the things I do, but if it's communications, especially unified communications, RingCentral does it.
And RingCentral developers, I, you can create a sandbox and use their accounts for free and get started trying out and st texts, starting meetings just like this one or a ton of other things with that. Again, today, amazing speaker award winner. Andrew [inaudible]. We talked about the faster web meets lean and mean PHP. We talk about people who know their stuff. Andrew is a certified Zandra engineers or five Zen architect just incredible guy all around. I have had the chance to get chat with him recently and just truly amazed by what he does. And of course, Andrew's book was rated one of the best PHP books all time.
So I feel like we live like like the master in our presence here. Be sure to check out his book online. And I think Andrew has even given out some books day as well. So sticker off for your chance to learn how to win a copy of his book, but also make sure supportive and share his book on Twitter or other social media. Again, great book from a great guy. With that, I'm going to stop sharing my screen and I'm going to turn over to Andrew who is good. Probably do a far better job of explaining things that I ever could. Andrew, you want to take it away?
See, now I have to say the first time Andrew showed me this screen blew me away already, but like I said, he stays. He's making nomad, PHP, classy. So Andrew, we got your screen. Love the backdrop and gala to take it.
I think we can safely say that the faster web is here to stay. So let's have a look at a few of the technologies that make up the fast win and that keep our world interconnected. When Google launched the faster web initiative, many projects that were to becoming part of it already existed. The faster web, more or less became an initiative that brought many projects to light and allow many new ones to be created. If we have a look back at the origins of the web as we know it today, we can see that many of the original specifications and standardized versions of the HTTP protocol were defined after some trial and error. We can also see that performance features like pipelining, which is the kipa life feature and cache control mechanisms were already included in the first standardized version of the HTTP protocol back in 1997 indeed, the fencer web was already effect before the word.
The most significant advances and faster web technologies were definitely edge site includes better known as ESI, which was thought as a way to meet the challenges of web infrastructure scaling by applying edge computing to it. This was a major milestone. Let's see why. Edge side includes also known as ESI, was a major step towards the faster web. It was originally formalized as a specification to be approved by the worldwide web consortium back in 2001 the idea was to decentralize web page content to the logical extremes of the network in order to avoid having all content requests being sent to the web server every single time. The specifications call for a new HTML tags that would allow HTTP cache servers to determine if certain parts of a page needed to be fetched from the original web server or if cash versions of those parts could be sent back to the client without having to query the server for it.
It is possible to think of ESI as a sort of HTML include feature that is used to assembly webpages, dynamic content from different external sources. Another faster when milestone was the fact that many browsers started to standardize client caching mechanisms in order to meet the requirements of the ESI standard. Still. Another one was the fact that forward proxy servers, our client caching servers were starting to be used for reverse proxy caching or a server caching. And finally the creation of reverse proxy cache servers like varnish, which aimed at quickly determining what where and when to cash passing bites on the network. Let's take the time to have a closer look at varnish. Shall we? Varnished? Cache is a reverse proxy cache server that partially implements ESI. It was originally thought out by its creators, Paul hitting cam, Anders Berg and dag Erling smart grab as being a highly needed replacement for squid, a well known HDP forward proxy cache server. The concept behind the project was to find a way to quickly manipulate bites that would be taken from passing network traffic and a way to determine what where and when to gash those bites. Many years later, varnish cache has become one of the most important HDP cash servers.
Indeed varnish cache has known worldwide adoption. It is now running on more than 3.4 million websites across the world. That is definitely success. These technologies are very powerful when combining them with client side caching. For example, client side caching focuses on reducing the number of requests needed to render a page in order to avoid network latency as much as possible. Nowadays, all major browsers offers support for these techniques and enabling these technologies on your website is as easy as sending it to additional headers or using library files that are already available on content delivery networks. Browser caching relies on cash control evaluation and response validation. These two models work through headers, specifically the cache control and E tag hitters. These headers are sent by the server to the browser in order to instruct it to avoid getting certain pages or files within a certain timeframe.
Content delivery network, so I distributed networks of proxy servers that allow for high availability and high performance distribution of common or popular web resources. You can also use CDNs as a reverse proxy cache servers for your website by modifying your DNS server in order to redirect web traffic to the CDM. Let's run varnish cache on our computer. First, start a Linux for PHP container and from there start installing the Python package manager. Then install certain packages like dock utils and Sphinx. Once those are completed, download varnishes, source code, unpack it and then configure it.
Once configuration is done, proceed to compile it using the make command compilation will only take a few minutes. Let's compilation is done. Enter the make install. This will install a varnish cache inside your container to make sure that you're proxying the correct server. Make sure that you enter the correct IP address. You can do this by asking Docker to give the IP addresses of all your containers. Once you have the IP address of your web server, enter the following command and varnish will immediately start crossing queries sent to your server
To test it,
Go to your browser and NTT the IP address of the varnish cache server. As you can see, we are getting the contents from the web server running varnish cache on your computer is just that simple.
Google's faster web initiative. Therefore made it possible to bring a whole set of tools to come and work together and new ones to be created with web performance in mind. One of the most important ones was definitely Google speedy module and the new version of the HTP protocol that came out of it speedy was a new session protocol that worked over an underlying TLS presentation layer and allow for many HDP speed optimizations and had the application layer speedy rapidly became a core element of the faster way and became in November of 2012 the basis of the next major revision of the HTTP protocol using the new protocol was as easy as activating SSL and enabling a module on the server. The new protocols, main new features were multiplexed and prioritized streams, server pushing and header compression.
The multiplex streams feature allow for mapping multiple requests and multiple streams on a single connection. These streams were by direction. It could be initiated by either the client or the server. Opening multiple streams over one single connection made it possible to avoid the overhead of establishing a new connection on each client server exchange, especially when downloading multiple resources in parallel to complete the rendering of a single page. Thus, this first feature made it possible to get rid of the limited number of possible connections when using the HTTP one protocol. Moreover, the streams were prioritized. This additional feature allowed the client to determine which resources should be sent over the wire first. Thus, it was possible to avoid the first in first out issue that arose when trying to do server pipelining. That is using the keep alive directive with the HDB one protocol. The new stream features made it possible for the server to push data to the client without responding to the client's request. This made communication by directional and allow the web server to anticipate the needs of the client. Indeed, even before the client had done parsing the HTML and determine all the files that would be necessary in order to render the page, the web server could push the files down the stream to the client, thus reducing the number of requests sent by the client in order to fetch all the necessary resources.
The third feature was header compression by compressing the often high number of HTTP headers and reducing them by as much as 85% of their original sizes. On average, the new protocol could cut up to a full second off the low time of mostly she could be transactions over the wire. Running an HTTP two enabled server on your computer is very easy. Using Linux for PHP, simply modify Apaches configuration file and make sure that you have enabled the SSL and he should DP two modules. Once this is done, simply modify the SSL configuration for Apache and make sure to add the protocols directive in the virtual host of your server. If your server is correctly configured and has its certificates, you can now run HTTP to simply run this curl command. You will see that the headers now show that you are in an HTTP two transaction from 1998 until today, many new benchmarking, load testing and monitoring tools were created in order to help measure web performance. One very well known benchmarking tool is siege. Siege is a low testing and benchmarking tool that allows for further analysis of a web servers performance. Let's begin by installing siege inside our Linux for PHP Docker container from the containers command line. Please download and decompress version four.zero dot two of siege.
Then please enter sieges source code directory to come pile in. Install the software, start by configuring siege, then come pilot by entry. The command make a few moments later. You will be able to enter the command make install in order to install siege inside the container. For these tests, we will be using the BC and our switches. B enables the benchmark mode. It means that there are no delays between iterations. C enables concurrency in order to perform multiple requests at the same time and are determines the number of requests to perform with each concurrent user. Let's launch the siege test now with 3000 concurrent users and a hundred requests per user. After a few moments you will obtain a report like this one. There were more than 25,000 hits and the server responded to all of these in a few seconds for report. Also shows the transaction rate, the concurrency, successful transactions and failed ones and the longest transactions. Many monitoring tools were also developed over the years. Let's have a look at CIC.
The tech stack was developed by influx data and is made of a series of integrated components that allow you to easily process time series data generated by different services through time. Tick is an acronym that is composed of the first letters of each main product of the monitoring suite, T S for Telegraph, which collects the information I as for influx DB, which is a time series database C is for chronograph, a graph tool that allows you to easily understand the collected data and finallyK is for capacitor and alert automation tool. In this example, we will replace chronograph by Grafana monitoring. Infrastructure. Performance is not only important to determine if applications and scripts are running as expected, but also allows for development of more advanced algorithms such as failure, prediction and unexpected behavior. Pattern recognition, thus making it possible to automate many aspects of performance monitoring. Let's begin by activating mud status on our Apache server from our Linux for PHP CLI. We will enter the following command. Once you have done this, you should be able to see the server's status report by browsing with Chrome to the following URL. The next step is to launch the Dixon in a new terminal window. We will type this command. Once we obtain the IP address of the new influx DB container. We can proceed to configure and launch [inaudible]
Now any second newly spawned terminal window, we will launch Griffina with the following command. Once this is done, we can log into Graffina. The login and password are admin. Once logged in, we can add a new data source. In our case, we will enter the address of our influx DB container that we obtained previously. The credentials to authenticate against the new influx DB data source, our user root and password route. We can now add this new data source for our Graffina container. We will now import a new dashboard from the Grafana website. When visiting the gruff on a website, we can easily find the unique ID number of each dashboard. This makes it very easy to then import the dashboard integral fun. Once imported Grafana will. Then start processing the data found in the influx database. This allows us to see all information on our server in real time.
Other faster web tools were also developed. One such tool that will help you further analyze the performance issues of web applications is page speed insights. Over the years, many performance tools were also developed. UI design became very important as not only objective time but perceived time became an issue when dealing with performance, but performance is also about perception. Time measurement depends on the moment of measurement and can vary depending on the complexity of the task to be performed. The psychological state of the user and the user's expectations as he might have defined them according to what he considers to be the software of reference when executing a certain task. Therefore a good manner in which an application does what it has to do also means that the software would have to meet the user's expectations as how to this computer program ought to do things. Hence quicker is not always better. The faster web was also about better understanding the principles behind UI design. When it comes to the perception of performance. Let's take the following simple example to illustrate how UI design principles can give us the impression of performance. So let's request a very slow script.
That would definitely qualify as slow. We will create a second HTML script that will do some adjuncts requests to the original one and display its progress on the screen. Let's run it now. As we can see, we have a throbbing and we have a message telling us that it is working
Now. Definitely that gave us the impression that everything was going faster when in fact it was half a second slower. Well, all these faster web technologies are great, but aren't we forgetting something? Aren't we forgetting something that's running on 70 to 80% of servers across the world? We have this funny feeling that maybe just maybe there might be an elephant in the room.
Yeah, we're talking about PHP. So was PHP ready for the faster web? Well, the short answer is not really. According to a study led by the hip hop compiler team at Facebook in May, 2010 PHP was the slow was language of the mall, so why was PHP so slow? Well, first of all, it's an interpreted language and not pre compiled. Second, it's dynamic symbol lookups were slow. Finally, it is a weak type language. When a language is dynamically type. That is to say it has loosely type variables. It a higher level
Of abstraction that boosts the developer's productivity but doesn't offer the best performance since it's compiler has more work to do when trying to determine the data types of experiments. It comes as no great surprise that strongly type languages have always had better performance at runtime than loosely type ones.
Many new tools and optimizations were developed over the years since PHP five dot. Three PHP now includes a fast CGI process manager that allows you to run much more secure, much faster and more reliable PHP code on web servers before PHP FBM. The default way to run PHP code on a web server was usually through the mod PHP module. What makes PHP FPM so interesting is the possibility for it to adapt itself to the number of incoming requests and spawn new processes in a pool of workers in order to scale to the growing demand. Moreover, running PHP this way allows for better script termination, more graceful server restarts, more advanced error reporting and server logging and find green tuning of the PHP environment for each and every PHP pool of workers. Through the demonization of the PHP binary. It has been reported by many high traffic websites that they have seen speed performance hikes of the order of 300% when changing from mod PHP to PHP FPM on their production servers.
Since PHP five dot five opcode caching is now available in PHPs core functionality when adding the enable all cache switch to the configure scrip at compile time. Generally speaking, Zen Oop cash will make any script from 8% to 80% fast. The more time is scripts, wall time is caused by the PHP binary itself, the more Oop cash will make a difference. But if the script's PHP code is very basic or if PHP is slowed down by latency due to input and output such as a stream to a file or a connection to a database, Oop cash will only slightly enhanced script performance. In all cases, Zen Oop cash will optimize PHP strip performance and should be enabled on all production servers. By default,
New features were added to the PHP language. PHP is basically synchronous language that wastes for a call function to return before presuming code execution I O calls are especially problematic if the called function has to wait for a stream to close before returning to the calling code. This becomes even worse when a PHP application has thousands of IO calls to do every few minutes. For example, since PHP five dot three it has become possible to interrupt PHPs normally saw of execution by using generators and thus to execute code as synchronously. As we can see, we have code that we'll be doing a curl request to the Google website. Now this wild loop will loop 10 times and each CRO requests we'll have to wait until the previous one completes before being able to execute itself. Now when running this subscript, we will see that the elapsed time is one point 24 seconds, which is a lot. Now if we were to run this code as synchronously, we would be able to do that in a fraction of a second. Here we will be using the curled multi in it function. We will be creating a synchronous requests for our 10 requests to the same website. Let's see how performance this a synchronous code is compared to the synchronous one
So let's run the synchronous code
Wow. Almost 10 times faster for the same result as synchronous code is definitely a tool for performance. So let's look at another example of a synchronous code. In order to bend or understand what's going on under the hood. As synchronous code relies on a main loop, this main loop will be processing each generator until the generator returns. Definitely in this case, we will be having fun with the little car race. Each generator will represent a car that will have to complete a certain number of laps before it can win the race. Let's run this little application and see a secretness code in action. We will run the code three times in order to better appreciate the synchronous nature of the code. Indeed, we should never come up with exactly the same result at the same speed with the new same number of laps, especially the certain cars seem to be going faster than others on your marks get set go. As we can see, each race gave a different result. This shows how a synchronous code is random in nature because we never know which part of the code will return. First
POSIX threads better known as piece shreds is a library that allows a computer program to execute multiple processes or threads concurrently by forking child processes from its parent process. The P threads library can be used in PHP making it there for possible to fork processes in the background while executing something else simultaneously. Thus, multithreading is another way to cope with latency in IO calls. Now let's have some fun bikes. It getting him multithreading script. To do so, we will run a Zen thread, safe version of Linux for PHP. Once the container is started, please enter the command Pechal install P threads to get the P threads library. Once a command is launched, compilation will begin in a few moments later. P threads will be installed, but it will be necessary to enable it in the PHP INI file. Please enter the following command to do so. Once this is done, it will be possible to execute our multithreading script. Let's have a look at the script. As we can see, we will be extending the thread class and we'll be using the run function to run multiple threads. That will be sleeping in a random delay. Once this is done, we will be starting each thread simultaneously
As we can see what should have taken possibly 30 seconds took moral less five to 10 seconds. Although the P threads library is not optimized in PHP, it can still be a lifesaver in certain occasions. Many new performance analysis tools were also developed. Static analysis tools like exa, Kat and PHP stand and dynamic ones like XD bone and black Fareol are great allies in making sure that PHP code is performed. Running Blackfire IO on your computer is as easy as entering the LF PHP, getting black fire command in a Linux for PHP container. Once you launched this Crip, it will automatically install all that you need to run Blackfire on your computer. Then simply enter the command Blackfire run at PHP and the name of your script.
Once it has done its work, it will give you a preliminary report and you can then look at the call graph on the website. This will give you the entire call stack of your script exclusive inclusive times and metrics which will allow you to do very precise diagnostic on your scripts. Oh, this was great, but important optimizations to the Zen engine were still needed. Facebook had been looking for a way to convert the weekly and dynamically type PHP into these strongly and statically type C plus. Plus, this is the hip hop transpire project was all about and this project led Facebook to hack HHVM and it's just in time compiler Meanwhiles and had been doing their own research and experiments to optimize the Zen engines ahead of time compiler. The greater part of these optimizations meant eliminating the performance overhead generated by certain PHB internal structural constructs and data structures by using the C compilers, internal logic in an optimized way. And by optimizing execution of PHP code. This was to be done by generating better quality intermediate representations of the source code by removing dead code, by reducing as much code as possible to a static representation. And by looking for a just in time compilers somewhere in PHPs future, the following Zen engine features had to be developed to do so. The abstract syntax tree static single assignment and type inference.
And that's when a very important announcement came in December, 2015 Zen released a new version of PHP and that is when we can say the faster web Mitt [inaudible].
Yeah, that's right. We're talking about PHP seven it was introduced in December, 2015 and had many new key features, strict typing, although PHP seven is still a loosely type language, it now offers the possibility district type variables and functions signatures
That is 33% less memory
What are the new key features is memory allocation of integers and floats. If you need to create a large number of variables, you should try to reuse them. S PHB sevens compiler will avoid reallocating memory and reuse the memory slots that have already been allocated. That is one third less memory. Still. Another feature was string interpolation and concatenation. String interpolation is now much faster than concatenation and what used to be true about concatenation performance is no longer the case. [inaudible]
Yeah, you've seen that, right? It's four times fast. Introducing PHP seven is immutable and packed. Raise any static or raise cash by O P cash and a pointer to the array is shared with any part of the goal that tries to access it or raise that. Our index with S and N integers are packed arrays. Yup. You've seen it, right. It's 10 times less memory and whew, isn't that a whopping 40 times faster. Wow. One last key feature is parameter references. Even though it is best to avoid passing it variable by reference to a function in order to avoid altering your application state outside of the function, [inaudible] makes it possible to pass variables by reference to functions in a highly optimized way, even if the reference is a mismatch. And boom, there it is up to 10,000 times faster with PHP seven dot. Two woo. No
[Inaudible] [inaudible] [inaudible] [inaudible]
Well there you go. That was the faster web. So I hope you all enjoyed the presentation today. Please leave your comments on joined in. I always like to read those and also as Mike mentioned at the beginning of the meeting today, I am giving out three copies of my book and at Mike's request they will be signed copies. So there you go. A bonus for that. If you have any questions on my presentation, please do not hesitate to contact me through Twitter or LinkedIn. You can also get in touch with me through my brand new blog. Andrew S K [inaudible] dot net. Again, my company is for each code factory. The website is E T I S T a.com. I am the lead developer for Linux for PHP. I imagine you sort of saw that in the presentation there. So go check out the website. There will be a major release before Christmas this year with plenty of documentation for them. Those who are looking for it. The website is Linux for php.net and finally I would like to thank Mike Stowe and the entire true EthnoMed PHB for having me on. And a special thank you to Cal Evans for inviting me originally. So thank you all for watching. And back to you Mike.
And this was absolutely amazing and I have to be honest like half the time I was just simply being blown by by the knowledge you're sharing. The other half the time I found myself trying not to like stand up and dance at Dorothy's PHC. Oh, it was a great presentation. I have a question for if they don't mind tackling it really quickly. And that is you shared a lot of different things that we can use to increase performance. What would be like the top one or two things you'd say? Look, if you can't do everything, at least do this to start?
Well the main issue with the performance of course is always input and output. So the worst of them all is networking of course. But anything in the file system also. So anything that you want to explore let's say to say, well, how can I speed up this application? Start by liking looking out for all the Iowa calls because that's the main point. So they're, I guess as synchronous programming would help you out a lot. Multithreading could be interesting also. And of course there's a lot of other technologies that we couldn't talk in this in this talk here at [inaudible], but all the no SQL databases or in memory databases, those are all things that could speed those things up. So I would, I would start by those things. If you're looking for immediate intervention on a server tomorrow morning, let's say.
That was great. That was great. Thank you so much. Once again. I really can't thank you enough for coming on or for the the tremendous presentation. You've done my only complaint is I had a presentation earlier at Northeast PHB today and yours has completely put me to shame.
Absolutely loved it. It's two different types of presentations, Mike. Two different things. Don't be shamed about it.
Oh, we'll go with that. I'll, we'll, we'll use that. All right. Let me share my screen here really quickly. Again, a huge, huge thank you to, to Andrew for an amazing presentation, sharing all this knowledge. Even just from a nomad PHP side, we have obviously a lot to go back and improve the performance from all the learnings. And another huge congratulations to Andrew on being named, having his book named one of the best PHP books of all time. As he mentioned Andrew has, yeah. And very generously wave three signed copies of the book to win a copy of the book. All we're going to ask you to do is to tweet about Andrew's talk and share his book on Twitter and just tag nomad PHP in that tweet. I know we have a lot of people around, a lot of different regions. Nobody was able to make the live meeting, so we will basically give away until September 30th. On September 30th we'll look at the tweets again, tweet out about Andrew's talk share what a great job he did a Sheriff's book. I think this is an invaluable resource, include nomad PHP and we'll pick three winners from that.
Also a huge thank you to Osby and RingCentral developers again for sponsoring. Again the work that ASMI does and raising awareness about mental illness and mental health and the developer communities is huge. If you're saying I wish I had somebody that I could come to my employer and just, you know, help them develop a program, help train them to really focus on mental health just as much as we do physical health and other things. Awesome. He is a great resource for that. Check them out at [inaudible] dot org and again, a huge thank you to RingCentral developers. Again, if you're looking for a voice text, SMS team, messaging meetings, facts, et cetera, you can find all that on RingCentral developers or developers. Dot ringcentral.com. They have API as they have STKs. They have bots, they have widgets, you name it, you can do it with a RingCentral developers.
Also, we have a, another great presentation coming up. So we have Tom two night, so I'll be 6:00 PM Pacific time on how to build a modern or M enable Epiduo the API. Huh. It's so complex. I can't even completely say it without having to take a pause. Be sure to check out his talk as well. And then next month we have two more great speakers. We have WebSockets and PHP by John [inaudible]. And then for European meeting we have pipelines. How do you use PSR? Seven CSR 15 and middleware with the [inaudible] framework for integrations with PHP. And that's by my former boss. Imagine like Willbanks last but not least, be sure to connect with us. You can tweet us at nomad PHP. Please follow us. We've got some exciting updates, exciting news, especially as we roll to the new subscription model.
You can find the lightning talks and videos on youtube.com/nomad PHP and be sure to join our Facebook group to find us. Just search for nomad PHP. Unfortunately, you can't have PHB in the Indian on Facebook, kind of a security measure that they put in there, but you will find us if you search for us. With that, that's all I have for this month's nomad PHP for the European meeting. We hope to see you at later today for the U S meeting and hope to see you all next month. Right. Thank you. And now, Andrew, thank you again.