 please can you put your mask on your face in the room it's mandatory yeah thank you it to have better performance so just let me adjust the title of the conf it's about PHP 2 again just before we start I have to remind everybody that we are still under strict mask mandate I'm sorry to be the guy who has to say that but it's still the fact so please put up your masks yeah hello everyone by anticipation sorry for my broken English I'm French and that's all okay I'm I'm here to speak about Drupal and PHP performances it's very important it's not a deep dive into performances with PHP it's just some tips and tricks and to have a better understanding how to how to have better performance with your code with your PHP ecosystem with your hosting that way some tips I would like to share with you okay so don't I'm Nicolas Perice I'm working at Echino and has a PHP lead the senior I come from Symphony world okay don't judge me but it's a very good community and a lot of best practice that's why I'm here this talk is not about web performances I don't speak about how tune your front end with some some tips it's not about this it's not a talk to to try to to give you some better tips to be a better coder better developer it's not this and it's not an architecture call okay architecture talk so let's go some Drupal performance generalities maybe some of these advice are abuse but let just me speak about for me it's very important to use the last version of your of your language PHP that's why when you use PHP 8 on your version it's very important why because you have immediate you have gains immediately it's very important you can you can have around seven percent of gain just to switch between set seven dot four and hate and hate dot one it's very important it's free and you can have better performance just to have great your PHP version the common things to say is to avoid to install a lot of modules why because when you install module you have the discovery phase into Drupal that it's very intensive operation you have a lot of code parsing but in production we don't want this we want to avoid to pass PHP files that don't we want to use that's why you need to short to bypass all the things that you block your performance the interesting things to be it's to be defensive I don't know if in the Drupal community you are very defensive it's a reference of defensive programming but it's very important to be defensive early exit and so on to try to reduce the runtime of your PHP runtime okay it's an important advice you can see a lot of literature on the internet it's very interesting the common things to do is to use the PHP CSS fixer to use FQFN to benefit of your up-code inlining function do you know what kind of code inlining no sorry but it's very important to attach on certain PHP function you can have a backslash before to try to optimize the up-code produced by the PHP engine and with this it's it's a really it can be a gain of performance inside the symphony framework it was a huge gain to prefix some PHP function with with a backslash it's not useful to backslash all their function inside your code but certain function provide up-code inlining and it's very important to use you can easily fix this with PHP CSS fixer sorry PHP CSS fixer inside the CI inside your development local development for example okay another thing is to use the container injection dependency like a symphonist usage you can use tag you can use compiler pass and other things to to avoid to to detect all your work and at the time inside your hook better you compile this a better you put this in the cache in the table container it's better the service provider base provide provide the base class to X to provide some interface to implement to which provides the definition service alteration by example who provides a compiler class into the container it's common with symphony but less with the looper and you use this it's very powerful avoid to load the necessary entities I think it's abuse because it's memory intensive sometimes it can be a CPU intensive avoid to make this it's it's my advice is not that's my opinion a way to use use for any needs sometimes write SQL row SQL with a dedicated cache is better than use the UI and use of use we don't want to to pass PHP that we don't want to use it's the same it's already the same okay for me sometimes write your dedicated code disable what you don't want production seems so used to me too and prefer usage of monologue who is using monologue in production good very good it's very powerful and you can create channel and then store lots of different logs and performance is really better that to use the watchdog watchdog is based on the database and we want want to deal with the database often because the TCP calls can be can be can be can be less sorry can be less powerful that's that's work with direct files or in PHP files so we want we don't want to make to perform some TCP calls because you have a lot of transaction TCP and check and so on we don't want this and you can log SQL query is the slow log a query and use the explain keyword to track bottleneck inside your SQL okay this is common but maybe not I don't know and very important things to know is use internal cache by default we're using this tunnel cache but it use it inside the database and we don't want to make this poor to have better performance in production I try to explain in the next chapter what is a cache back end and how to configure it and how to optimize it it's important okay here is a schema from AWS to how to host scalable Drupal and Drupal with performance it's not it's common for large projects okay there is no no pain point here you have for example the usage of CDN here is CloudFront can be fastly Akamai or other things you you need to to have better performance you need to use S3 storage instead of EFS or NFS montage point because here is a really fast history protocol is faster than access the file system it's very interesting to use sorry it's very interesting to use S3 instead of instead of the file system you have some module in Drupal to use S3 file system by example it's it can be a mess to it can be difficult to configure sometimes but if you have encrypt encrypt links this module is not perfect but it's really good to to begin to work with here you have the scalability with autoscaling group we deploy a C2 instance and each instance contains a Drupal instance which managed service here we have memcached we can use Redis I really prefer to use Redis I speak about Redis after Aurora it's a RDS managed service you can use PostgreSQL you have better performances with PostgreSQL than your usage of MySQL or MariaDB all my Drupal project turns with PostgreSQL you need to patch some modules to adjust type-in thing inside SQL but it's really well I don't speak about PostgreSQL because we don't have the time but it's really a powerful database and so on you have the file system amount here and you have the autoscaling the traffic is increased autoscaling creates a C2 instance with different Drupal instance this is a basic scalability of Drupal you can use instead of use the usage of Amazon Cloud front you can use here varnish cache but the problem in this type of scalability you need to invalidate varnish on each on each a C2 instance on its content instance of your application don't use varnish use CDN it's better you can invalidate your your your cache with a pure drill module with different adapter there is an adapter adapter for Cloud front there is an adapter for Akamai and so on so it can be it's better why I would like to share we use this type of our architecture it's because you need to understand all the stream between your different pieces inside your infrastructure and how to optimize it boop ad its PHP but PHP it's a proxy pass for main gynics I advise to use in gynics really better than apache and you you send request inside in gynics which are reverse proxy you send it to varnish varnish speaks with the backend and and so on there is a lot of TCP connection between all these pieces and you have a lot you you lost the time you lost time in each layer okay we we don't want this and we want to try to be faster than checks we call the DB we have the response we call them it's not possible to make this and it's very difficult to parallelize this this communication so here is hold the tweet from 3G it's a human comprehension of the time which is going on inside your computer it's very important latency numbers and every programmer should know and high as you can see an internet connection on HTTP external call or TCP can is really really huge 40 milliseconds is equal to four years in human time when you speak with the database this is the time okay you can already hear different cache level from your CPU and we want to be very fast we want the date the data in our pocket very fastly that's why we don't we use the cache level one as soon as possible but this is a CPU we don't we can't perform but PHP most of the time this with Linux operating system and Linux operating system make a lot of calls for a system call and the system call deals with level one level two level three okay okay you can just generate just for fun I think it's very interesting to know and to have in mind so what is a cache backend everybody knows what is a cache backend inside dupal okay I don't you must know you can create as been as you want and you can create a learn or connect and learn to these bins I want it's very easy to create a been a dedicated been dedicated storage location to store your dedicated data it's not a good idea to put the data inside the core bins or module it's you I prefer to have an isolation to invalidate my cache after and you you can create this how you create how you can can you create a been it's very easy to inside the DI it's suddenly an appointment you need to subscribe to a tag and so on okay a been is is directly connect with the cash back and each cash back and implements the cash back and interface you can implement your dedicated cash back and with which is already implemented is one cash back and nobody okay I'm alone okay the bins are collected by the compiler list cash bins pass okay don't just for information you have the compiler pass detect the bin because you have to try to attack and and so I don't want to go further in details here okay but you need to know different cash back end to have a better configuration of your performance with this okay the default the default back end for Drupal it's provided by the core is database back end what does it mean everything when Drupal put some items in the cache it store it into the database the default behavior okay it's slow really slow too slow we it's not if you have a huge traffic if you need to end a lot of requests it's not the good solution to use inside your application okay moreover there is a default constant that is set into the database back end or just a part of here of the database back end the default max was what does it mean each cash table contains by default only 5,000 of lines that's all if you want to store more you trigger an invalidation cash into your production server we don't want this it's a performance killer you can upgrade the default behavior inside the settings like this and you can configure for each bins the number of rows by example the cash container table no need to have this value only one rows okay it's sharing between the request there is different type of other cash the new cash back end I don't speak with you it's not important the memory cash back end not important the usage for test the PHP cache back end it's the faster cache that we will be used but the problem is that when the he creates some PHP file and at the right time PHP file I put inside the opcode if opcode is enabled but we don't it's hard to invalidate that was it's not a good idea to put your cash in your cash inside and if you are in a auto scaling infra your cash is inside the your front end one not in front end two it's not shared between you can't create an FS because it's so and so it's not it's not a good solution but it's the faster so the Dupal core creates this the fast chain back end who is using the fast chain back end we are three okay okay the fashion back end is very very interesting because when you when you deal with you you want to to get some high terms and the first thing that this is cash makes it's to fetch IPCU IPCU is a memory in cash database it's a shortcut but you can you can we can say this and if it is found you see is a green pass if I miss phone if I'm a return is really fast because it's in memory and with IPCU is it shared memory between your different PHP process okay okay it's it's perfect but if the it times I have not found you you need to fetch the other back end your other back end can be ready this meme cash D PostgreSQL MySQL whatever it times is cash inside the the back end it times items I store into a PCU and value as a return the next time I want the items it's inside IPCU it's faster that was change fast back end okay nothing to say more about this but we we can configure ready to have better performance we don't want to use the database so we need to store data in some location and the best locations for me is ready which is using ready with is Drupal okay it's common it's good so to use ready you need to install ready slags is it's not so difficult to understand the the not easy step to to understand it's the redefinition of the bootstrap content definition here we win when Drupal is booted it is need to to understand how to deal with the database with this that's why we need to create a small container symphony container not symphony dependent injection container a very small container which is is able to work with the true container which is stored inside ready or inside your database or inside a PCU or inside whatever okay that's why you need to redefine some service and create this service in here we are really fine as the the the bootstrap content definition by default you can get the content the if you want you can get the the service content definition from an API by example can be an ID you can make a lot of things with this is very powerful and it's made during the Drupal kernel log and after you you register some services in sewer settings and by default we are saying use cache backend dot redis it's a back it's cache backend provided by the ready this module to to use okay normally is is a common the common way to use the redis it's not mandatory to to enable redis because this module can work without enable redis service are registered you can use the service no problem and ready is just the ready module just provide some statistics and we don't want this because it's going to the database we don't want to make this okay look it just so tips no need to enable the ready module and when ready this is active on your production is Ponteon gives this schema you can see that the database load is decreased significantly it's better okay but by default you use the PHP serialized function the normalizer with PHP serialize and unsurrealized function we can go further with IG binary which is using IG binary to deal with redis and other things good it's perfect so here is an example on how to install install IG binary with redis inside the docker file common use case the important things is to say to reduce to compile with the IPCU with the sorry with the IG binary extension and what what is IG binary IG binary is a drop-in replacement for the standard PHP serializer IG binary PHP data structures in compact binary form it means the strings are stored and not in the compact way binary way not with the string a standard string the aim is to compact the message and to have better better unsurrealization inside your application with this you reduce the TCP tram by a percent it's depend on your application you save time you save memory you say a lot of things is it's a very very cool there is IG binary but there is also another extension which is compact but compact compact is less less have a less performance as IG binary okay IG binary is working fine with PHP 8.2 it's not it's not a problem you can you can use the two the two the two things let me let me show the next sorry here is a proof you don't trust me but it's the truth and you have the benchmark comparison into the GitHub repository of IG binary here is a standard with PHP 8 okay by default one we are we are low we have lower lower time with the serialized function PHP function is better to serialize but we have better time with unsurrealized function than PHP and it's very important because we serialize sometimes and we unsurrealize often it's not important to when you serialize data it's not the fastest way to make it's not important but to unsurrealize your application makes a lot of time you're during your request with the handle of the request okay so to handle IG binary with this inside the Dupal the Dupal application not so difficult here we have the bootstrap container definition we create we are creating the service or dedicated service to handle IG binary here we are defined the serialization dot IG binary and underscore serializer it's a small class that implements the serializer interface from the core and just here you substitute serialize with IG binary underscore serialize and you have gains it's cool I think it's not so difficult to to implement it's an easy way to make this okay so now we know how cacheback can works you can play with the different configuration of your bins and by default we are setting the whole bins into a ready-disk cache but the bootstrap and discovery very important bins to Dupal to boot I use the cacheback can change fast I want to use a PCU before to use ready-disk what does it mean okay and after you are different bins I don't know how it's not a recipe so you need to to detect your bins and find and make some adjustments and for other bins you can define maybe cacheback and database because for these bins particularly you have better performance with okay you can play with and fine and make some fine tuning to have better configuration so now we I'm speaking about PHP opcode if you don't know what is PHP opcode you have the opcode explained here with this schema on here okay as the important things to to know is that the parsing PHP file create token with Alexa and so on it's intensive that's why we won't we don't want to make this operation for all our request we want to to share how by code between PHP that's why we need to cache it and to cache it it just enable the opcode the the opaque age inside your pick your application if you want to monitor your your opcode you can use this tool cache tool is very powerful tool it gives some use some statistic inside your application and you can invalidate the opcode I think it's a good good project to to enable to enable the PHP of code you need to enable the extension here and you need to increase some value because Drupal it's like symphony it's used a lot of lot of files and we need to compute this inside the we don't want to break our opcode opcache that what we need to increase the memory construction we need to increase the max-accelerated files it's how to just your system detects other files it's important and I think the most important things to know it's to create this opcache dot validate under our timestamp equals to zero what does it mean if you go to your production and you write some PHP in production don't make this on but but you save your files nothing is happened because we don't have the revalidation of your cash it's already in the opcode cache and you are safe with this but when you are deploying the next version of your application you need to invalidate the cache inside PHP fpm it's important you imagine you deploy a new version but you don't invalidate your opcache you are selling partially your older application with a new one it's don't lose so but with this you are really really really games okay so now we are speaking about PHP and PHP fpm not just here the real-cache size need to be increased because there is a lot of a lot of a lot of files inside your dopal projects that's why we need to put an extra an extra settings here an extra we are to increase the value of these settings you need to make this same for the real-cache TTL here you have the reason why because when PHP detects your files in fact the phpc function you use system calls function like stat a stat is intense is very intensive for your OS that's why we want to put the cache inside the PHP engine and not inside the system engine okay there is a lot of things to understand here it's very important some tips here you can use a jubinary with a PCU to have better performance a PC dot serializer equals to a jubinary so now you have a jubinary strings binary strings into the PCU cache very fast you can dub the auto loader like this with the class map auto auto what does it mean you files are detected and written into PHP file and that's finished there is no more discovery you know the file if the file is missing the file is missing problem but with this you have a lot of performance due to stat function inside your OS and this thing is very interesting you can set the composer auto loader into a PCU instead of PHP file to have better performance it's very it's some tips but you can have some gains with this how about PHP FPM as you know there is three three different type of worker type static dynamic on-demand most of the time we use the on-demand we use the dynamic dynamic worker definition but it's not a good solution to have better performance for low traffic site you need to use on-demand worker okay and for high traffic site you need to use the static worker you define exactly the number of workers that you want and that's all because when you are in the static on-demand you have an overhead to generate the PHP to for the PHP FPM process it's not it's not a good idea to have better performance use static but you need to make some statistics about your PHP FPM before to address this configuration here you have small calculation method to find how to set up correctly for the dynamic type and on-demand type the number of workers that you want and you need to preproduction server use stress test and load testing to to see how your PHP FPM behavior is you can use a hay it's an utility written in go very powerful in fun and K6 K6 this is the same written go and very very powerful to when you are in a stress situation on your infrastructure on our application you can enable the PHP FPM statue pass FPM statue which give you some information in direct of your child of your children and memory consumption and so on you have different you can get the result into design XML or HTML if you want to make this you need to create some engine location it's not so difficult you can search on the web it's very interesting to do and when you are when you are set if you want to have better settings of this it's inside your preproduction server and not on your production server we try to be preventive and not we don't want to wait to be in to be in production to adjust some settings okay another thing is to we can speak but I don't know if I was the time it's to speak about a lot of PHP FPM load balancing you can load balance your PHP FPM socket between different parts of your application by the hardest things to do here is to is to split your two pal application it's not so easy to bypass the admin pass and to bypass the front-end pass and our different IP I pass here it's just a pattern on the URI but it's not maybe the the better way to do okay but you can load balance your PHP FPM and so on have different configuration of your full definition to a better isolation and performance and better adjusting your PHP FPM to speak about engine x we we we can use different type of cache inside engine x but the aim with this is an invalidation of this of this cache you can use a fast CGE cache directive to configure your cache is very very powerful because we don't speak with PHP because the result is already in cache you can say an example of the configuration here but we have the same with the proxy cache if you have engine x as a reverse proxy to varnish my example varnish is in the sandwich mode which is called with the backend you can pro before to proxy cache to varnish you can have a cache here to have better performance inside your reverse proxy before to to have the response of varnish you have the response from engine x which is in mode a reverse proxy better because we we are not go down inside the infrastructure we are in the highest pieces of your info okay it's not droop all but it's very powerful you can enable HTTP 2 or HTTP 3 if you enable HTTP 2 it's easy it's only to add HTTP 2 into the listen directive you have gain directly easy and powerful most of the hosting makes this that's very powerful and if you are not sure you can use a quick the new protocol based on UDP HTTP 3 but it's still experimental on engine x you can enable jzip or brought broadly compression if you can active broadly compression inside your engine x configuration really better than jzip and you can use cache assets with a expires max like this you can set a lot of a lot of extension just an example here with this you have a good performance with engine x there is a lot of things to to say but we don't have the time to speak about but this is for me this is the base to have better performance with PHP with engine x the end I would like to speak about black fire which is using a black fire with Drupal some people okay it's very black fire is a code profiling the aim is to find bottleneck inside the runtime of your application Drupal under the request under the request and give the response and response and makes a lot of a lot of things between these two parts and you write code inside these two parts and x such prof or black fire tries to to help to find bottleneck inside your application xh xh prof is all projects from Facebook it's maybe it's ugly it's not so fun to use better it's to use black fire you are you have a hack edition for free but you just have the work work time and the CPU work time you don't have network I O database it's it's expensive it's a tool that is expensive but very powerful we use it a lot of things on our project and why we using this it's to create black fire insertion we are monitoring our performance during the build phase of our application it means we can create some basic test like this here okay and we don't want to have by example we don't want to have so much SQL query on the homepage we don't want to have a peak memory super inferior to a superior to this value we don't want to have a network out superior to this value maybe because I want to speak to radius it's a network calls you don't want to use a lot of TCP call okay and when you write this it's very interesting to to make and when you are stressing your application you can audit your performance during your build phase you can you can block the size ID because the performance is not here and you could you can review your mr and write on write to better coding okay you can you can couple this with their boost of SQL CI to monitor your web performance and with this you are really good performance inside your application okay I encourage to try to use this type of tool it's you can win a lot of things a lot of games as the conclusion to my last advice is searching for performance resolution can be expensive in terms of cost and time it's not so easy to track the performance and you install this it's not directly again for some some tips you need to work with try to find what is going on inside your application it's not so easy this type of tips don't make better PHP code okay you only need to have a better conception try to be defensive try to write less cost right to be decoupled from decoupled from Drupal there is a lot of things to do before but as you must know that it's it's a cost okay for your project no need to focus on micro optimization is set versus Rikki exists by example it's not it's not a problem you can use rector to make this you can use PHP as fixer you can use PHP standard rules you can make a lot of things that helps to have better performance in micro optimization okay no need to focus on it search for performance is not for all project typologies if you work for a small project you don't need to make this it's not a problem but if you work with a big company with a huge traffic you have this problem that normally you have the team has the time to try to make the things that you do to have better performance for me it's a collaborative work it's not only a PHP worker you need to work with your PHP team share your knowledge often you need to speak with your DevOps team PHP and DevOps for me must be the same but you you can you can if you have a dedicated team you need to speak with how to PHP works how to maybe they have some some knowledge to share with with you it's very important you need to understand how the system works our Linux works it's very important to try to find performance that's why the communication with the system system team if you if you have it's important for the front-end part you need to deal with HTTP to performance web performance and other things do not only focus on PHP but it's ecosystem and when you are writing PHP code it's PHP plus PHP FPM plus varnish plus redis plus name cash D plus OS OS OS operating system and a lot of things you need to understand all the pieces and my advice be not only a site builder be a deep dive PHP developer try to to search how PHP work try to find the things how it's working how Dupal is working how the core is build how the core is what is the conception of the core for example try to dive into each subject to have a better understanding and to find the best solution to your problem and sorry but Dupal is not always a good solution for for the project Dupal is a good project huge project but sometimes you don't need to deploy Dupal to make your project you can use PHP row you can use the symphony la ravelle whatever let me ask you can use WordPress maybe I don't know but just keep in mind as I do I don't know I don't use WordPress okay but for me it's my opinion Dupal isn't as an architect it is not always a good solution it serves a lot of problematics for a huge project but not often you can replace some parts of Dupal with other things and try to be creative to to create some microservices and so okay so thank you you have some feedback don't hesitate to come with me or fill this out thank you excuse me we have one question from