SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
Anti-patterns in php
Sep, 2020
Ahmed
Who is this guy
?
● Ahmed
● In the industry for about 9 years, I
worked as SRE, PM but mostly
Software engineer.
● I love all languages but PHP a little
bit more.
● Opensource advocate.
● Low cost, high-risk actions.
● Composer.
● Inheritance.
● Standardization
● Testing
● Logging
● Observability
● Continuous integration
● Containers
Anti-patterns in php
Low cost, high-risk actions
Anti-patterns in php
PHP is easy and makes everything sounds that everything will work correctly on
it's own.
Low cost, high-risk actions
Low cost, high-risk actions
After you deploy your app to production, always expect:
- To be asked to extend certain feature.
- Add new feature.
- To get bug reports and be able to understand it and fix it.
Low cost, high-risk actions
Every technical action makes it easier or harder to :
- Quickly modify the code base and make the PMs/CXOs happy.
- Make you and your teammates happy when they fix a bug.
So, while coding ...
Anti-patterns in php
Composer
Please, please, do not use the Death Star,
The Death Star is a bomb waiting to explode in the
team face
always use version constraints.
Composer
Please do not edit composer files manually at all
Please, please, use composer commands, they are super easy.
“The new composer package is working locally but not working on the server”
Extending classes
● Each parent should not many children. It becomes hard to change the
parent even with 100% testing coverage.
● System design is thrown out of the window with the overuse of inheritance,
easy solutions like visibility change for the sake of easiness over-power the
design and leads to GOD-classes eventually very easily.
● This is the exact recipe to create a bad monolith
Extending classes
Inheritance is not the only way
to extend a functionality.
Also taxes are high
on inheritance these days.
Extending classes
Inheritance is not the only way
to extend a functionality,
for example composition.
https://en.wikipedia.org/wiki/Composition_over_inheritance
Fun Fun Function: Composition over Inheritance
Depending on the environment
Avoid depending on the environment, for example
Instead: you can use environment variables
“I can not test it, It works only on PROD”
Standardization
https://xkcd.com/927/
Standardization
Standardization
Standardization
API with no OpenAPI/Swagger specs is not an API.
But It’s a good way to waste time and frustration everyone.
https://github.com/zircote/swagger-php
https://api-platform.com/
Standardization
Kafka messages without avro schema is the best way to make debugging a
nightmare.
Also please do not serialize 1 MB of data in kafka please, Kafka is not MySql.
Testing
Testing positive cases only
is not great idea
Logging
Logging
“It’s not working”
Logging
“We do not know what happened”.
“This is my best guess”.
“It’s only 1 customer of 1000, I’m sure he need to clear the cache.”
Logging
Logs are insurance policy,
you don’t care about it till you need them, then it’s too late.
Bare minimum: please please log any failures to perform external operations or
operations impacting business process.
(dbs, , kafka, curl, … )
Logging
Example of stressful and also useless logging messages
“Error happened”
“Order not processed”
“Life is hard”
Logging
Log level matters,
if everything is WARNING or ERROR then nothing is important.
Observability
“Do you know that your website is down ?”
“A customer called and said he sees something in checkout says 503.”
Observability
Create alert for website downtime.
Also watch the business impact,
“no orders in the last hour”.
Simplest tool is uptimerobot , similar tools.
Observability
Watching/having-and-alert for error logs.
Simplest tool is sentry.io, similar tools.
Continuous integration
The team discussed best practices, and after a lengthy discussion, they agreed.
Continuous integration
Best practices are amazing, but we are humans, we always do mistakes.
“We are only humans” said by ahmed , 11 sep 2020
Automate anything you can in your application pipelines, save your team the
hassle.
Gitlab ci, bitbucket ci, circle ci, buildkite ci, …..
Containers
Docker is a company with a tool after it’s name.
The technology name is containers.
Please use “containers” instead of “docker”.
Containers
In short, containers images are compressed archives contains
- your application code itself
- The binaries that run it (php fpm)
- The binaries config (php.ini)
Containers
Please use aggressive opcache options on docker/containers on PROD
Opcache.validate_timestamps => 0
Each deployment is a new container with new memory,
no need to worry about this.
Containers
Storage in containers are ephemeral,
please do not attempt to write on it or use for anything,
even for logging, especially for logging.
Use GCS or AWS S3 or anything else.
Send logs to centralized logging.
Containers
Containers startup time should be very very small
In other words:
Composer install on container startup is a bad idea.
Npm install on on container startup is a a bad idea.
Containers
The same container image must be
deployable to production, staging and local.
If not, debugging becomes impossible and testing extremely hard.
More resources
Video: PHPUnit Best Practices (Sebastian Bergmann)
Video collection: Best practices in PHP
Article: Eliminating Visual Debt
Questions ?
Thank you for listening
Twitter: ama_abdou
WWW: ahmd.io

Más contenido relacionado

La actualidad más candente

Lessons Learned From Applications That Kicked Titanium's Ass
Lessons Learned From Applications That Kicked Titanium's AssLessons Learned From Applications That Kicked Titanium's Ass
Lessons Learned From Applications That Kicked Titanium's Ass
Kevin Whinnery
 
scriptcs - scripted C#, REPL and script extensibility
scriptcs - scripted C#, REPL and script extensibilityscriptcs - scripted C#, REPL and script extensibility
scriptcs - scripted C#, REPL and script extensibility
Filip W
 

La actualidad más candente (20)

The Power Of Refactoring (PHPNW)
The Power Of Refactoring (PHPNW)The Power Of Refactoring (PHPNW)
The Power Of Refactoring (PHPNW)
 
Cucumber.js: Cuke up your JavaScript!
Cucumber.js: Cuke up your JavaScript!Cucumber.js: Cuke up your JavaScript!
Cucumber.js: Cuke up your JavaScript!
 
HTML5 for dummies
HTML5 for dummiesHTML5 for dummies
HTML5 for dummies
 
Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
 
TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
TGT#20 - Automated Tests Only For Testers - Kasper KulikowskiTGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspec
 
Follow these reasons to know java’s importance
Follow these reasons to know java’s importanceFollow these reasons to know java’s importance
Follow these reasons to know java’s importance
 
Myphp-busters: symfony framework (PHPCon.it)
Myphp-busters: symfony framework (PHPCon.it)Myphp-busters: symfony framework (PHPCon.it)
Myphp-busters: symfony framework (PHPCon.it)
 
那些年,我們一起玩的萬花筒(Kaliedoscopic)
那些年,我們一起玩的萬花筒(Kaliedoscopic)那些年,我們一起玩的萬花筒(Kaliedoscopic)
那些年,我們一起玩的萬花筒(Kaliedoscopic)
 
Myphp-busters: symfony framework
Myphp-busters: symfony frameworkMyphp-busters: symfony framework
Myphp-busters: symfony framework
 
Testing Storm components with Groovy and Spock
Testing Storm components with Groovy and SpockTesting Storm components with Groovy and Spock
Testing Storm components with Groovy and Spock
 
BDD in PHP - Behat
BDD in PHP - BehatBDD in PHP - Behat
BDD in PHP - Behat
 
composer_talk_20160209
composer_talk_20160209composer_talk_20160209
composer_talk_20160209
 
REPL-driven development with pry
REPL-driven development with pry  REPL-driven development with pry
REPL-driven development with pry
 
CI
CICI
CI
 
Lessons Learned From Applications That Kicked Titanium's Ass
Lessons Learned From Applications That Kicked Titanium's AssLessons Learned From Applications That Kicked Titanium's Ass
Lessons Learned From Applications That Kicked Titanium's Ass
 
Behat - human-readable automated testing
Behat - human-readable automated testingBehat - human-readable automated testing
Behat - human-readable automated testing
 
BDD with Behat
BDD with BehatBDD with Behat
BDD with Behat
 
scriptcs - scripted C#, REPL and script extensibility
scriptcs - scripted C#, REPL and script extensibilityscriptcs - scripted C#, REPL and script extensibility
scriptcs - scripted C#, REPL and script extensibility
 
Node & Express as Workflow Tools
Node & Express as Workflow ToolsNode & Express as Workflow Tools
Node & Express as Workflow Tools
 

Similar a PHP Mega Meetup, Sep, 2020, Anti patterns in php

Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
Omid Vahdaty
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortals
cgack
 

Similar a PHP Mega Meetup, Sep, 2020, Anti patterns in php (20)

2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
 
10 Code Anti-Patterns to Avoid in Software Development.pdf
10 Code Anti-Patterns to Avoid in Software Development.pdf10 Code Anti-Patterns to Avoid in Software Development.pdf
10 Code Anti-Patterns to Avoid in Software Development.pdf
 
Comment améliorer le quotidien des Développeurs PHP ?
Comment améliorer le quotidien des Développeurs PHP ?Comment améliorer le quotidien des Développeurs PHP ?
Comment améliorer le quotidien des Développeurs PHP ?
 
12 tricks to avoid hackers breaks your CI / CD
12 tricks to avoid hackers breaks your  CI / CD12 tricks to avoid hackers breaks your  CI / CD
12 tricks to avoid hackers breaks your CI / CD
 
Enterprise PHP (PHP London Conference 2008)
Enterprise PHP (PHP London Conference 2008)Enterprise PHP (PHP London Conference 2008)
Enterprise PHP (PHP London Conference 2008)
 
Dictionary Within the Cloud
Dictionary Within the CloudDictionary Within the Cloud
Dictionary Within the Cloud
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
TxJS 2011
TxJS 2011TxJS 2011
TxJS 2011
 
DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
 
What every C++ programmer should know about modern compilers (w/ comments, AC...
What every C++ programmer should know about modern compilers (w/ comments, AC...What every C++ programmer should know about modern compilers (w/ comments, AC...
What every C++ programmer should know about modern compilers (w/ comments, AC...
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortals
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Android reverse engineering - Analyzing skype
Android reverse engineering - Analyzing skypeAndroid reverse engineering - Analyzing skype
Android reverse engineering - Analyzing skype
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Advantages of golang development services & 10 most used go frameworks
Advantages of golang development services & 10 most used go frameworksAdvantages of golang development services & 10 most used go frameworks
Advantages of golang development services & 10 most used go frameworks
 
Is Python still production ready ? Ludovic Gasc
Is Python still production ready ? Ludovic GascIs Python still production ready ? Ludovic Gasc
Is Python still production ready ? Ludovic Gasc
 
Sonatype DevSecOps Leadership forum 2020
Sonatype DevSecOps Leadership forum 2020Sonatype DevSecOps Leadership forum 2020
Sonatype DevSecOps Leadership forum 2020
 

Más de Ahmed Abdou (7)

Opesnource and jobs
Opesnource and jobsOpesnource and jobs
Opesnource and jobs
 
Cloud and Devops
Cloud and DevopsCloud and Devops
Cloud and Devops
 
About Linux , Shake your brain
About Linux , Shake your brainAbout Linux , Shake your brain
About Linux , Shake your brain
 
Future is now,Future is Opensource
Future is now,Future is OpensourceFuture is now,Future is Opensource
Future is now,Future is Opensource
 
You're open source
You're open sourceYou're open source
You're open source
 
المصادر المفتوحة , فرصة
المصادر المفتوحة , فرصةالمصادر المفتوحة , فرصة
المصادر المفتوحة , فرصة
 
Menufya SFD 2012
Menufya SFD 2012 Menufya SFD 2012
Menufya SFD 2012
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

PHP Mega Meetup, Sep, 2020, Anti patterns in php

  • 1.
  • 3. Who is this guy ? ● Ahmed ● In the industry for about 9 years, I worked as SRE, PM but mostly Software engineer. ● I love all languages but PHP a little bit more. ● Opensource advocate.
  • 4.
  • 5. ● Low cost, high-risk actions. ● Composer. ● Inheritance. ● Standardization ● Testing ● Logging ● Observability ● Continuous integration ● Containers Anti-patterns in php
  • 6. Low cost, high-risk actions Anti-patterns in php
  • 7. PHP is easy and makes everything sounds that everything will work correctly on it's own. Low cost, high-risk actions
  • 8. Low cost, high-risk actions After you deploy your app to production, always expect: - To be asked to extend certain feature. - Add new feature. - To get bug reports and be able to understand it and fix it.
  • 9. Low cost, high-risk actions Every technical action makes it easier or harder to : - Quickly modify the code base and make the PMs/CXOs happy. - Make you and your teammates happy when they fix a bug.
  • 10. So, while coding ... Anti-patterns in php
  • 11. Composer Please, please, do not use the Death Star, The Death Star is a bomb waiting to explode in the team face always use version constraints.
  • 12. Composer Please do not edit composer files manually at all Please, please, use composer commands, they are super easy. “The new composer package is working locally but not working on the server”
  • 13. Extending classes ● Each parent should not many children. It becomes hard to change the parent even with 100% testing coverage. ● System design is thrown out of the window with the overuse of inheritance, easy solutions like visibility change for the sake of easiness over-power the design and leads to GOD-classes eventually very easily. ● This is the exact recipe to create a bad monolith
  • 14. Extending classes Inheritance is not the only way to extend a functionality. Also taxes are high on inheritance these days.
  • 15. Extending classes Inheritance is not the only way to extend a functionality, for example composition. https://en.wikipedia.org/wiki/Composition_over_inheritance Fun Fun Function: Composition over Inheritance
  • 16. Depending on the environment Avoid depending on the environment, for example Instead: you can use environment variables “I can not test it, It works only on PROD”
  • 20. Standardization API with no OpenAPI/Swagger specs is not an API. But It’s a good way to waste time and frustration everyone. https://github.com/zircote/swagger-php https://api-platform.com/
  • 21. Standardization Kafka messages without avro schema is the best way to make debugging a nightmare. Also please do not serialize 1 MB of data in kafka please, Kafka is not MySql.
  • 22. Testing Testing positive cases only is not great idea
  • 25. Logging “We do not know what happened”. “This is my best guess”. “It’s only 1 customer of 1000, I’m sure he need to clear the cache.”
  • 26. Logging Logs are insurance policy, you don’t care about it till you need them, then it’s too late. Bare minimum: please please log any failures to perform external operations or operations impacting business process. (dbs, , kafka, curl, … )
  • 27. Logging Example of stressful and also useless logging messages “Error happened” “Order not processed” “Life is hard”
  • 28. Logging Log level matters, if everything is WARNING or ERROR then nothing is important.
  • 29. Observability “Do you know that your website is down ?” “A customer called and said he sees something in checkout says 503.”
  • 30. Observability Create alert for website downtime. Also watch the business impact, “no orders in the last hour”. Simplest tool is uptimerobot , similar tools.
  • 31. Observability Watching/having-and-alert for error logs. Simplest tool is sentry.io, similar tools.
  • 32. Continuous integration The team discussed best practices, and after a lengthy discussion, they agreed.
  • 33. Continuous integration Best practices are amazing, but we are humans, we always do mistakes. “We are only humans” said by ahmed , 11 sep 2020 Automate anything you can in your application pipelines, save your team the hassle. Gitlab ci, bitbucket ci, circle ci, buildkite ci, …..
  • 34. Containers Docker is a company with a tool after it’s name. The technology name is containers. Please use “containers” instead of “docker”.
  • 35. Containers In short, containers images are compressed archives contains - your application code itself - The binaries that run it (php fpm) - The binaries config (php.ini)
  • 36. Containers Please use aggressive opcache options on docker/containers on PROD Opcache.validate_timestamps => 0 Each deployment is a new container with new memory, no need to worry about this.
  • 37. Containers Storage in containers are ephemeral, please do not attempt to write on it or use for anything, even for logging, especially for logging. Use GCS or AWS S3 or anything else. Send logs to centralized logging.
  • 38. Containers Containers startup time should be very very small In other words: Composer install on container startup is a bad idea. Npm install on on container startup is a a bad idea.
  • 39. Containers The same container image must be deployable to production, staging and local. If not, debugging becomes impossible and testing extremely hard.
  • 40. More resources Video: PHPUnit Best Practices (Sebastian Bergmann) Video collection: Best practices in PHP Article: Eliminating Visual Debt
  • 41. Questions ? Thank you for listening Twitter: ama_abdou WWW: ahmd.io