SlideShare a Scribd company logo
PrestaShop securityimprovements and optimizations
[object Object]
Team of 6 developers & integrators
400 Prestashop installed – ranging from 0.9.6 to 1.3.1
Shared hosting – cluster of 10+ machines (load balancers, web servers, file servers, database servers) About us ?
4 Pillars of performance ,[object Object]
Our focus: Server-side code (1-st tier, php + sql)
Network, transport protocols
Client-side code (2-nd tier: html + css + javascript) ,[object Object]
Your architecture has to be efficient (good planning) You have to code using best practices (don't do **obviously** stupid things) But prefer rather maintability and readibility of code over the speed When speed is not critical (i.e. real time systems, high traffic sites), you can improve it in  later iterations When to optimize?
Measure first! You should know bottlenecks. Benchmark different scenarios and configs Going Linux? Test Linux, not Win. There are differences  Will have 10000 products in your store? Test your modules with db of 10000, not 5 Is a 1% improvement worth of additional work? What about 5%? 10%? Try to estimate coding cost vs. hardware cost Sometimes it's just cheaper to add RAM What to optimize?
Small performance gains Using (int) instead of intval() can be even 4 X faster But overall gain is negligable (unless you are Facebook) Code executed once Tools::setCookieLanguage could be improved, but it is executed once Mythical optimisations ( ” vs ' ) But ”$a $b $c” … is faster than $a.” ”.$b.” ”.$c Whatshouldn'tbeoptimised
Server load: ab, siege, multi-mechanize ... Databaseload: MySql Slow Query Log, mysql proxy, ... EXPLAIN  PHP: xdebug, dbg, xhprof ... Network / client side Yslow, firebug, WebKitinspector, dynaTrace AJAX, fiddler, google webmaster tools How to measure?
Server: Difficult task, often impossible on shared hostings Ask your admin CPU is rarely a bottleneck, generally indicates problems with suboptimal code RAM is cheap but not unlimited – attention to memory consuming scripts Typical problem: gd + jpg -> 2 Mb on disk, 33 Mb decompressed into memory Ramdisk for often accessed, not critical files (frameworks, configuration, tmp)  Most common bottleneck: I/O (filesystem, dbs) Improving infrastructure
Every call to fs costs, depending the OS, filesystem and number of files  Always use absolute paths in require / include Performance may start to degrade if you have more than 50 000 files in a directory Each product has image, each image has 6 thumbnails Debian + Apache 1.3 (shared hosting, nfs): Filesystem # Files Glob('*') exec. in sec. file_exists / sec. 1000 4,59 36000 11000 13,30 21000 65000 55,81 1475 122000 142,16 718
Directory content splitting: img/p/534-189-small.jpg becomes img/p/small/534-189.jpg Reading transparently via .htaccess RewriteRule (.*)/p/([^/]*)homejpg $1/p/home/$2home.jpg Writingtransparently via class  	if (!imageResize($file, 				$dir.$imageType['name'].'/'.$language['iso_code'].'-default-	'.stripslashes($imageType['name']).'.jpg', ... Solution
Database! ,[object Object]
Avoid to using too many JOINSSELECT * FROM ps_feature` f LEFT JOIN ps_feature_lang` fl ON ( f.`id_feature` = fl.`id_feature` AND fl.`id_lang` = 1) WHERE f.`id_feature` = 1SELECT * FROM ps_feature_lang` fl WHER fl.`id_feature` = 1 AND fl.`id_lang` = 1  Version Tables Columns Without index 1.1.0.5 88 458 50 1.2.0.5 134 670 50 1.3.10 135 679 2 (cool! :)
Use VIEWS instead of complicated SELECTS Are you needing ps_connections & ps_connections_page? If you are expecting high traffic, thay can rise 10+ Mb / day Database
Big problem - non unique queries 1.3.10, simulation of command process: Index – search – authentication – order (11 pages total)  3001 SQL queries, but only 1314 uniques! (44%)  PHP - SQL
Repeatedqueries
Non–optimisedqueries
Best is use mysql proxy or memcachedNot always possible Do not resolve overhead of unnecessary calls  Use internal cacheCan be scoped or globalPrestashop partially uses scoped cacheEasy to implement, tune, and … forget Each method / class is responsable for caching its query results Solutions
static public function getCurrency($id_currency){ 	return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'currency` 	WHERE `deleted` = 0 AND `id_currency` = '.intval($id_currency)); 	} static public functiongetCurrency($id_currency){ 	if (!isset(self::$_cache[$id_currency]))	{ 		self::$_cache[$id_currency] = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'currency` WHERE `deleted` = 0 AND `id_currency` = '.intval($id_currency)); 	} 	return self::$_cache[$id_currency]; 	} Scoped cache
[object Object]
Catches all output
Harder to implement
Some queries can be repeated but expecting different result (->cart)
Needs kind of "blacklist"
Once implemented, makes application maintenance much easier
Should be implemented as core featureGlobal cache
[object Object],	return preg_match('/^[a-z0-9!#$%'*+=?^`{}|~_-]+[.a-z0-	9!#$%'*+=?^`{}|~_-]*@[a-z0-9]+[._a-z0-9-]*[a-z0-9]+$/ui', 	$email); ,[object Object],	return filter_var($email, FILTER_VALIDATE_EMAIL); ,[object Object],	if (strpos($email, '@')!==false) ,[object Object],preg_replace('/"/', 'amp;quot;', $value) 	Faster: str_replace('"', '"', $value) Avoiding regexpSome people, when confronted with a problem, think  “I know, I'll use regular expressions.” Now they have two problems. (jwz)
[object Object],return preg_match('/^([^<>{}]|<br >)*$/ui', $text); 	return preg_match('/^(?:[^<>{}]|<br >)*$/ui', $text); 	?: = non capturing group (no memory allocation!) ,[object Object],return trim($table,'a..zA..Z0..9_') == ''; 	equals to 	return preg_match('/^[a-z0-9_-]+$/ui', $table); 	but is up to 2 times faster! Avoidingregexp (2)
foreach($cart->getProducts() as $product)    if ($orderStatus->logable)       ProductSale::addProductSale(intval($product['id_product']), intval($product['cart_quantity'])); Should be: if ($orderStatus->logable)      foreach($cart->getProducts() as $product)             ProductSale::addProductSale(intval($product['id_product']), intval($product['cart_quantity'])); (no need to test if in every iteration if it does not change) Use conditions wisely
// Send an e-mail to customer if ($id_order_state!= _PS_OS_ERROR_ AND $id_order_state!= _PS_OS_CANCELED_ AND $customer->id) { $invoice = new Address(intval($order->id_address_invoice)); $delivery = new Address(intval($order->id_address_delivery)); $carrier = new Carrier(intval($order->id_carrier)); $delivery_state= $delivery->id_state ? new State(intval($delivery->id_state)) : false; $invoice_state= $invoice->id_state ? new State(intval($invoice->id_state)) : false; $data = array(  '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone, '{invoice_other}' => $invoice->other, {order_name}' => sprintf("#%06d", intval($order->id)), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), intval($order->id_lang), 1), '{carrier}' => (strval($carrier->name) != '0' ? $carrier->name : Configuration::get('PS_SHOP_NAME')), '{payment}' => $order->payment, Can you spot the problem?
'{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false, false)); if (is_array($extraVars)) 	$data = array_merge($data, $extraVars); // Join PDF invoice if (intval(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number) { 	$fileAttachment['content'] = PDF::invoice($order, 'S'); 	$fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', intval($order->id_lang)).sprintf('%06d', $order->invoice_number).'.pdf'; 	$fileAttachment['mime'] = 'application/pdf'; } else 	$fileAttachment= NULL; if ($orderStatus->send_email AND Validate::isEmail($customer->email)) 	Mail::Send(intval($order->id_lang), 'order_conf', 'Order confirmation', $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment); $this->currentOrder = intval($order->id); return true; } $this->currentOrder = intval($order->id); return true;

More Related Content

What's hot

Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006
Mark Curphey
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterCodeIgniter Conference
 
Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)
xSawyer
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
Stalin Thangaraj
 
OO Perl with Moose
OO Perl with MooseOO Perl with Moose
OO Perl with MooseNelo Onyiah
 
Introduction To Moose
Introduction To MooseIntroduction To Moose
Introduction To Moose
Mike Whitaker
 
DataFu @ ApacheCon 2014
DataFu @ ApacheCon 2014DataFu @ ApacheCon 2014
DataFu @ ApacheCon 2014
William Vaughan
 
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
Amazon Web Services
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptNone
 
Spock
SpockSpock
Spock
nklmish
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
Craig Kerstiens
 
Code with style
Code with styleCode with style
Code with style
Clayton Parker
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
Jeremy Coates
 
You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012l3rady
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
xSawyer
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
Elizabeth Smith
 
JavaFest. Philipp Krenn. Scale Elasticsearch for Your Java Applications
JavaFest. Philipp Krenn. Scale Elasticsearch for Your Java ApplicationsJavaFest. Philipp Krenn. Scale Elasticsearch for Your Java Applications
JavaFest. Philipp Krenn. Scale Elasticsearch for Your Java Applications
FestGroup
 
Getting Hiera and Hiera
Getting Hiera and HieraGetting Hiera and Hiera
Getting Hiera and Hiera
Puppet
 
Moose Best Practices
Moose Best PracticesMoose Best Practices
Moose Best Practices
Aran Deltac
 

What's hot (20)

Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
 
Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
 
OO Perl with Moose
OO Perl with MooseOO Perl with Moose
OO Perl with Moose
 
Introduction To Moose
Introduction To MooseIntroduction To Moose
Introduction To Moose
 
DataFu @ ApacheCon 2014
DataFu @ ApacheCon 2014DataFu @ ApacheCon 2014
DataFu @ ApacheCon 2014
 
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Spock
SpockSpock
Spock
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
 
Code with style
Code with styleCode with style
Code with style
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
 
You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
 
JavaFest. Philipp Krenn. Scale Elasticsearch for Your Java Applications
JavaFest. Philipp Krenn. Scale Elasticsearch for Your Java ApplicationsJavaFest. Philipp Krenn. Scale Elasticsearch for Your Java Applications
JavaFest. Philipp Krenn. Scale Elasticsearch for Your Java Applications
 
Getting Hiera and Hiera
Getting Hiera and HieraGetting Hiera and Hiera
Getting Hiera and Hiera
 
Moose Best Practices
Moose Best PracticesMoose Best Practices
Moose Best Practices
 

Similar to Good practices for PrestaShop code security and optimization

Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Amplify your stack - Jsfoo pune 2012
Amplify your stack - Jsfoo pune 2012Amplify your stack - Jsfoo pune 2012
Amplify your stack - Jsfoo pune 2012threepointone
 
BigDataCloud meetup - July 8th - Cost effective big-data processing using Ama...
BigDataCloud meetup - July 8th - Cost effective big-data processing using Ama...BigDataCloud meetup - July 8th - Cost effective big-data processing using Ama...
BigDataCloud meetup - July 8th - Cost effective big-data processing using Ama...BigDataCloud
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
Capacity Management from Flickr
Capacity Management from FlickrCapacity Management from Flickr
Capacity Management from Flickrxlight
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTour
Wim Godden
 
Everyone loves PHP
Everyone loves PHPEveryone loves PHP
Everyone loves PHP
Abhijit Das
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
Mariano Iglesias
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: Backend
Võ Duy Tuấn
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Jonathan Klein
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - Goodies
Jerry Emmanuel
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate Works
Goro Fuji
 
Rails and security
Rails and securityRails and security
Rails and security
Andrey Tokarchuk
 
12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Indexwebhostingguy
 
Google Gears
Google GearsGoogle Gears
Google Gears
silenceIT Inc.
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4
alexsaves
 
Scaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approachScaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approach
Jinal Jhaveri
 
Website Security
Website SecurityWebsite Security
Website SecurityCarlos Z
 
Website Security
Website SecurityWebsite Security
Website Security
MODxpo
 

Similar to Good practices for PrestaShop code security and optimization (20)

Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Amplify your stack - Jsfoo pune 2012
Amplify your stack - Jsfoo pune 2012Amplify your stack - Jsfoo pune 2012
Amplify your stack - Jsfoo pune 2012
 
BigDataCloud meetup - July 8th - Cost effective big-data processing using Ama...
BigDataCloud meetup - July 8th - Cost effective big-data processing using Ama...BigDataCloud meetup - July 8th - Cost effective big-data processing using Ama...
BigDataCloud meetup - July 8th - Cost effective big-data processing using Ama...
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Capacity Management from Flickr
Capacity Management from FlickrCapacity Management from Flickr
Capacity Management from Flickr
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTour
 
Everyone loves PHP
Everyone loves PHPEveryone loves PHP
Everyone loves PHP
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: Backend
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - Goodies
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate Works
 
Rails and security
Rails and securityRails and security
Rails and security
 
12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index
 
Security.ppt
Security.pptSecurity.ppt
Security.ppt
 
Google Gears
Google GearsGoogle Gears
Google Gears
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4
 
Scaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approachScaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approach
 
Website Security
Website SecurityWebsite Security
Website Security
 
Website Security
Website SecurityWebsite Security
Website Security
 

More from PrestaShop

Réussir l'internationalisation de sa boutique e-commerce
Réussir l'internationalisation de sa boutique e-commerceRéussir l'internationalisation de sa boutique e-commerce
Réussir l'internationalisation de sa boutique e-commerce
PrestaShop
 
PrestaShop v.1.5 Alpha 1 : découvrez le Multi-boutique !
PrestaShop v.1.5 Alpha 1 : découvrez le Multi-boutique !PrestaShop v.1.5 Alpha 1 : découvrez le Multi-boutique !
PrestaShop v.1.5 Alpha 1 : découvrez le Multi-boutique !PrestaShop
 
Bc3 atelier new_quest
Bc3 atelier new_questBc3 atelier new_quest
Bc3 atelier new_questPrestaShop
 
Barcamp 3 PrestaShop - Atelier Découverte de So-Colissimo
Barcamp 3 PrestaShop - Atelier Découverte de So-ColissimoBarcamp 3 PrestaShop - Atelier Découverte de So-Colissimo
Barcamp 3 PrestaShop - Atelier Découverte de So-Colissimo
PrestaShop
 
Barcamp 3 PrestaShop - Atelier Découverte de PrestaShop v.1.4
Barcamp 3 PrestaShop - Atelier Découverte de PrestaShop v.1.4Barcamp 3 PrestaShop - Atelier Découverte de PrestaShop v.1.4
Barcamp 3 PrestaShop - Atelier Découverte de PrestaShop v.1.4
PrestaShop
 
Barcamp 3 PrestaShop - Atelier Intégration
Barcamp 3 PrestaShop - Atelier IntégrationBarcamp 3 PrestaShop - Atelier Intégration
Barcamp 3 PrestaShop - Atelier Intégration
PrestaShop
 
Barcamp 3 PrestaShop - Atelier PrestaShop / eBay
Barcamp 3 PrestaShop - Atelier PrestaShop / eBayBarcamp 3 PrestaShop - Atelier PrestaShop / eBay
Barcamp 3 PrestaShop - Atelier PrestaShop / eBay
PrestaShop
 
Barcamp 3 PrestaShop - Découvrez le webservice et la version mobile de Presta...
Barcamp 3 PrestaShop - Découvrez le webservice et la version mobile de Presta...Barcamp 3 PrestaShop - Découvrez le webservice et la version mobile de Presta...
Barcamp 3 PrestaShop - Découvrez le webservice et la version mobile de Presta...
PrestaShop
 
Barcamp 3 PrestaShop - Conférence Ergonomie et Tunnel de commande
Barcamp 3 PrestaShop - Conférence Ergonomie et Tunnel de commandeBarcamp 3 PrestaShop - Conférence Ergonomie et Tunnel de commande
Barcamp 3 PrestaShop - Conférence Ergonomie et Tunnel de commande
PrestaShop
 
Barcamp 3 PrestaShop - PrestaShop v.1.5 se dévoile !
Barcamp 3 PrestaShop - PrestaShop v.1.5 se dévoile !Barcamp 3 PrestaShop - PrestaShop v.1.5 se dévoile !
Barcamp 3 PrestaShop - PrestaShop v.1.5 se dévoile !
PrestaShop
 
Barcamp 3 PrestaShop - Ouverture
Barcamp 3 PrestaShop - OuvertureBarcamp 3 PrestaShop - Ouverture
Barcamp 3 PrestaShop - Ouverture
PrestaShop
 
Barcamp 3 PrestaShop - Conférence Optimisations et Hébergement de votre site ...
Barcamp 3 PrestaShop - Conférence Optimisations et Hébergement de votre site ...Barcamp 3 PrestaShop - Conférence Optimisations et Hébergement de votre site ...
Barcamp 3 PrestaShop - Conférence Optimisations et Hébergement de votre site ...
PrestaShop
 
Barcamp 3 PrestaShop - Témoignage Office Depot
Barcamp 3 PrestaShop - Témoignage Office DepotBarcamp 3 PrestaShop - Témoignage Office Depot
Barcamp 3 PrestaShop - Témoignage Office Depot
PrestaShop
 
Barcamp 3 PrestaShop - Conférence Réseaux Sociaux - Locita
Barcamp 3 PrestaShop - Conférence Réseaux Sociaux - LocitaBarcamp 3 PrestaShop - Conférence Réseaux Sociaux - Locita
Barcamp 3 PrestaShop - Conférence Réseaux Sociaux - Locita
PrestaShop
 
Barcamp 3 PrestaShop - Conférence Blog-Ecommerce
Barcamp 3 PrestaShop - Conférence Blog-EcommerceBarcamp 3 PrestaShop - Conférence Blog-Ecommerce
Barcamp 3 PrestaShop - Conférence Blog-Ecommerce
PrestaShop
 
Performance et optimisation de PrestaShop
Performance et optimisation de PrestaShopPerformance et optimisation de PrestaShop
Performance et optimisation de PrestaShop
PrestaShop
 
Installation & Configuration - PrestaShop
Installation & Configuration - PrestaShopInstallation & Configuration - PrestaShop
Installation & Configuration - PrestaShop
PrestaShop
 
Créer et intégrer son thème PrestaShop
Créer et intégrer son thème PrestaShopCréer et intégrer son thème PrestaShop
Créer et intégrer son thème PrestaShop
PrestaShop
 
Sécurité et performance, comment bien optimiser PrestaShop
Sécurité et performance, comment bien optimiser PrestaShopSécurité et performance, comment bien optimiser PrestaShop
Sécurité et performance, comment bien optimiser PrestaShop
PrestaShop
 
Retour sur la version 1.3 de PrestaShop
Retour sur la version 1.3 de PrestaShopRetour sur la version 1.3 de PrestaShop
Retour sur la version 1.3 de PrestaShop
PrestaShop
 

More from PrestaShop (20)

Réussir l'internationalisation de sa boutique e-commerce
Réussir l'internationalisation de sa boutique e-commerceRéussir l'internationalisation de sa boutique e-commerce
Réussir l'internationalisation de sa boutique e-commerce
 
PrestaShop v.1.5 Alpha 1 : découvrez le Multi-boutique !
PrestaShop v.1.5 Alpha 1 : découvrez le Multi-boutique !PrestaShop v.1.5 Alpha 1 : découvrez le Multi-boutique !
PrestaShop v.1.5 Alpha 1 : découvrez le Multi-boutique !
 
Bc3 atelier new_quest
Bc3 atelier new_questBc3 atelier new_quest
Bc3 atelier new_quest
 
Barcamp 3 PrestaShop - Atelier Découverte de So-Colissimo
Barcamp 3 PrestaShop - Atelier Découverte de So-ColissimoBarcamp 3 PrestaShop - Atelier Découverte de So-Colissimo
Barcamp 3 PrestaShop - Atelier Découverte de So-Colissimo
 
Barcamp 3 PrestaShop - Atelier Découverte de PrestaShop v.1.4
Barcamp 3 PrestaShop - Atelier Découverte de PrestaShop v.1.4Barcamp 3 PrestaShop - Atelier Découverte de PrestaShop v.1.4
Barcamp 3 PrestaShop - Atelier Découverte de PrestaShop v.1.4
 
Barcamp 3 PrestaShop - Atelier Intégration
Barcamp 3 PrestaShop - Atelier IntégrationBarcamp 3 PrestaShop - Atelier Intégration
Barcamp 3 PrestaShop - Atelier Intégration
 
Barcamp 3 PrestaShop - Atelier PrestaShop / eBay
Barcamp 3 PrestaShop - Atelier PrestaShop / eBayBarcamp 3 PrestaShop - Atelier PrestaShop / eBay
Barcamp 3 PrestaShop - Atelier PrestaShop / eBay
 
Barcamp 3 PrestaShop - Découvrez le webservice et la version mobile de Presta...
Barcamp 3 PrestaShop - Découvrez le webservice et la version mobile de Presta...Barcamp 3 PrestaShop - Découvrez le webservice et la version mobile de Presta...
Barcamp 3 PrestaShop - Découvrez le webservice et la version mobile de Presta...
 
Barcamp 3 PrestaShop - Conférence Ergonomie et Tunnel de commande
Barcamp 3 PrestaShop - Conférence Ergonomie et Tunnel de commandeBarcamp 3 PrestaShop - Conférence Ergonomie et Tunnel de commande
Barcamp 3 PrestaShop - Conférence Ergonomie et Tunnel de commande
 
Barcamp 3 PrestaShop - PrestaShop v.1.5 se dévoile !
Barcamp 3 PrestaShop - PrestaShop v.1.5 se dévoile !Barcamp 3 PrestaShop - PrestaShop v.1.5 se dévoile !
Barcamp 3 PrestaShop - PrestaShop v.1.5 se dévoile !
 
Barcamp 3 PrestaShop - Ouverture
Barcamp 3 PrestaShop - OuvertureBarcamp 3 PrestaShop - Ouverture
Barcamp 3 PrestaShop - Ouverture
 
Barcamp 3 PrestaShop - Conférence Optimisations et Hébergement de votre site ...
Barcamp 3 PrestaShop - Conférence Optimisations et Hébergement de votre site ...Barcamp 3 PrestaShop - Conférence Optimisations et Hébergement de votre site ...
Barcamp 3 PrestaShop - Conférence Optimisations et Hébergement de votre site ...
 
Barcamp 3 PrestaShop - Témoignage Office Depot
Barcamp 3 PrestaShop - Témoignage Office DepotBarcamp 3 PrestaShop - Témoignage Office Depot
Barcamp 3 PrestaShop - Témoignage Office Depot
 
Barcamp 3 PrestaShop - Conférence Réseaux Sociaux - Locita
Barcamp 3 PrestaShop - Conférence Réseaux Sociaux - LocitaBarcamp 3 PrestaShop - Conférence Réseaux Sociaux - Locita
Barcamp 3 PrestaShop - Conférence Réseaux Sociaux - Locita
 
Barcamp 3 PrestaShop - Conférence Blog-Ecommerce
Barcamp 3 PrestaShop - Conférence Blog-EcommerceBarcamp 3 PrestaShop - Conférence Blog-Ecommerce
Barcamp 3 PrestaShop - Conférence Blog-Ecommerce
 
Performance et optimisation de PrestaShop
Performance et optimisation de PrestaShopPerformance et optimisation de PrestaShop
Performance et optimisation de PrestaShop
 
Installation & Configuration - PrestaShop
Installation & Configuration - PrestaShopInstallation & Configuration - PrestaShop
Installation & Configuration - PrestaShop
 
Créer et intégrer son thème PrestaShop
Créer et intégrer son thème PrestaShopCréer et intégrer son thème PrestaShop
Créer et intégrer son thème PrestaShop
 
Sécurité et performance, comment bien optimiser PrestaShop
Sécurité et performance, comment bien optimiser PrestaShopSécurité et performance, comment bien optimiser PrestaShop
Sécurité et performance, comment bien optimiser PrestaShop
 
Retour sur la version 1.3 de PrestaShop
Retour sur la version 1.3 de PrestaShopRetour sur la version 1.3 de PrestaShop
Retour sur la version 1.3 de PrestaShop
 

Recently uploaded

Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
SOFTTECHHUB
 
Brand Analysis for an artist named Struan
Brand Analysis for an artist named StruanBrand Analysis for an artist named Struan
Brand Analysis for an artist named Struan
sarahvanessa51503
 
amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05
marketing317746
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
Adam Smith
 
An introduction to the cryptocurrency investment platform Binance Savings.
An introduction to the cryptocurrency investment platform Binance Savings.An introduction to the cryptocurrency investment platform Binance Savings.
An introduction to the cryptocurrency investment platform Binance Savings.
Any kyc Account
 
Authentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto RicoAuthentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto Rico
Corey Perlman, Social Media Speaker and Consultant
 
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdfModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
fisherameliaisabella
 
Exploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social DreamingExploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social Dreaming
Nicola Wreford-Howard
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
Adam Smith
 
-- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month ---- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month --
NZSG
 
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s DholeraTata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Avirahi City Dholera
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
agatadrynko
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
dylandmeas
 
Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024
Top Forex Brokers Review
 
buy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accountsbuy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accounts
Susan Laney
 
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Lviv Startup Club
 
Top mailing list providers in the USA.pptx
Top mailing list providers in the USA.pptxTop mailing list providers in the USA.pptx
Top mailing list providers in the USA.pptx
JeremyPeirce1
 
The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...
balatucanapplelovely
 
In the Adani-Hindenburg case, what is SEBI investigating.pptx
In the Adani-Hindenburg case, what is SEBI investigating.pptxIn the Adani-Hindenburg case, what is SEBI investigating.pptx
In the Adani-Hindenburg case, what is SEBI investigating.pptx
Adani case
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
Adam Smith
 

Recently uploaded (20)

Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
 
Brand Analysis for an artist named Struan
Brand Analysis for an artist named StruanBrand Analysis for an artist named Struan
Brand Analysis for an artist named Struan
 
amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
 
An introduction to the cryptocurrency investment platform Binance Savings.
An introduction to the cryptocurrency investment platform Binance Savings.An introduction to the cryptocurrency investment platform Binance Savings.
An introduction to the cryptocurrency investment platform Binance Savings.
 
Authentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto RicoAuthentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto Rico
 
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdfModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
 
Exploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social DreamingExploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social Dreaming
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
 
-- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month ---- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month --
 
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s DholeraTata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
 
Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024
 
buy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accountsbuy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accounts
 
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
 
Top mailing list providers in the USA.pptx
Top mailing list providers in the USA.pptxTop mailing list providers in the USA.pptx
Top mailing list providers in the USA.pptx
 
The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...
 
In the Adani-Hindenburg case, what is SEBI investigating.pptx
In the Adani-Hindenburg case, what is SEBI investigating.pptxIn the Adani-Hindenburg case, what is SEBI investigating.pptx
In the Adani-Hindenburg case, what is SEBI investigating.pptx
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
 

Good practices for PrestaShop code security and optimization

  • 2.
  • 3. Team of 6 developers & integrators
  • 4. 400 Prestashop installed – ranging from 0.9.6 to 1.3.1
  • 5. Shared hosting – cluster of 10+ machines (load balancers, web servers, file servers, database servers) About us ?
  • 6.
  • 7. Our focus: Server-side code (1-st tier, php + sql)
  • 9.
  • 10. Your architecture has to be efficient (good planning) You have to code using best practices (don't do **obviously** stupid things) But prefer rather maintability and readibility of code over the speed When speed is not critical (i.e. real time systems, high traffic sites), you can improve it in  later iterations When to optimize?
  • 11. Measure first! You should know bottlenecks. Benchmark different scenarios and configs Going Linux? Test Linux, not Win. There are differences Will have 10000 products in your store? Test your modules with db of 10000, not 5 Is a 1% improvement worth of additional work? What about 5%? 10%? Try to estimate coding cost vs. hardware cost Sometimes it's just cheaper to add RAM What to optimize?
  • 12. Small performance gains Using (int) instead of intval() can be even 4 X faster But overall gain is negligable (unless you are Facebook) Code executed once Tools::setCookieLanguage could be improved, but it is executed once Mythical optimisations ( ” vs ' ) But ”$a $b $c” … is faster than $a.” ”.$b.” ”.$c Whatshouldn'tbeoptimised
  • 13. Server load: ab, siege, multi-mechanize ... Databaseload: MySql Slow Query Log, mysql proxy, ... EXPLAIN PHP: xdebug, dbg, xhprof ... Network / client side Yslow, firebug, WebKitinspector, dynaTrace AJAX, fiddler, google webmaster tools How to measure?
  • 14. Server: Difficult task, often impossible on shared hostings Ask your admin CPU is rarely a bottleneck, generally indicates problems with suboptimal code RAM is cheap but not unlimited – attention to memory consuming scripts Typical problem: gd + jpg -> 2 Mb on disk, 33 Mb decompressed into memory Ramdisk for often accessed, not critical files (frameworks, configuration, tmp) Most common bottleneck: I/O (filesystem, dbs) Improving infrastructure
  • 15. Every call to fs costs, depending the OS, filesystem and number of files Always use absolute paths in require / include Performance may start to degrade if you have more than 50 000 files in a directory Each product has image, each image has 6 thumbnails Debian + Apache 1.3 (shared hosting, nfs): Filesystem # Files Glob('*') exec. in sec. file_exists / sec. 1000 4,59 36000 11000 13,30 21000 65000 55,81 1475 122000 142,16 718
  • 16. Directory content splitting: img/p/534-189-small.jpg becomes img/p/small/534-189.jpg Reading transparently via .htaccess RewriteRule (.*)/p/([^/]*)homejpg $1/p/home/$2home.jpg Writingtransparently via class  if (!imageResize($file, $dir.$imageType['name'].'/'.$language['iso_code'].'-default- '.stripslashes($imageType['name']).'.jpg', ... Solution
  • 17.
  • 18. Avoid to using too many JOINSSELECT * FROM ps_feature` f LEFT JOIN ps_feature_lang` fl ON ( f.`id_feature` = fl.`id_feature` AND fl.`id_lang` = 1) WHERE f.`id_feature` = 1SELECT * FROM ps_feature_lang` fl WHER fl.`id_feature` = 1 AND fl.`id_lang` = 1 Version Tables Columns Without index 1.1.0.5 88 458 50 1.2.0.5 134 670 50 1.3.10 135 679 2 (cool! :)
  • 19. Use VIEWS instead of complicated SELECTS Are you needing ps_connections & ps_connections_page? If you are expecting high traffic, thay can rise 10+ Mb / day Database
  • 20. Big problem - non unique queries 1.3.10, simulation of command process: Index – search – authentication – order (11 pages total) 3001 SQL queries, but only 1314 uniques! (44%) PHP - SQL
  • 23. Best is use mysql proxy or memcachedNot always possible Do not resolve overhead of unnecessary calls Use internal cacheCan be scoped or globalPrestashop partially uses scoped cacheEasy to implement, tune, and … forget Each method / class is responsable for caching its query results Solutions
  • 24. static public function getCurrency($id_currency){ return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'currency` WHERE `deleted` = 0 AND `id_currency` = '.intval($id_currency)); } static public functiongetCurrency($id_currency){ if (!isset(self::$_cache[$id_currency])) { self::$_cache[$id_currency] = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'currency` WHERE `deleted` = 0 AND `id_currency` = '.intval($id_currency)); } return self::$_cache[$id_currency]; } Scoped cache
  • 25.
  • 28. Some queries can be repeated but expecting different result (->cart)
  • 29. Needs kind of "blacklist"
  • 30. Once implemented, makes application maintenance much easier
  • 31. Should be implemented as core featureGlobal cache
  • 32.
  • 33.
  • 34. foreach($cart->getProducts() as $product)    if ($orderStatus->logable)       ProductSale::addProductSale(intval($product['id_product']), intval($product['cart_quantity'])); Should be: if ($orderStatus->logable)      foreach($cart->getProducts() as $product)             ProductSale::addProductSale(intval($product['id_product']), intval($product['cart_quantity'])); (no need to test if in every iteration if it does not change) Use conditions wisely
  • 35. // Send an e-mail to customer if ($id_order_state!= _PS_OS_ERROR_ AND $id_order_state!= _PS_OS_CANCELED_ AND $customer->id) { $invoice = new Address(intval($order->id_address_invoice)); $delivery = new Address(intval($order->id_address_delivery)); $carrier = new Carrier(intval($order->id_carrier)); $delivery_state= $delivery->id_state ? new State(intval($delivery->id_state)) : false; $invoice_state= $invoice->id_state ? new State(intval($invoice->id_state)) : false; $data = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone, '{invoice_other}' => $invoice->other, {order_name}' => sprintf("#%06d", intval($order->id)), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), intval($order->id_lang), 1), '{carrier}' => (strval($carrier->name) != '0' ? $carrier->name : Configuration::get('PS_SHOP_NAME')), '{payment}' => $order->payment, Can you spot the problem?
  • 36. '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false, false)); if (is_array($extraVars)) $data = array_merge($data, $extraVars); // Join PDF invoice if (intval(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number) { $fileAttachment['content'] = PDF::invoice($order, 'S'); $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', intval($order->id_lang)).sprintf('%06d', $order->invoice_number).'.pdf'; $fileAttachment['mime'] = 'application/pdf'; } else $fileAttachment= NULL; if ($orderStatus->send_email AND Validate::isEmail($customer->email)) Mail::Send(intval($order->id_lang), 'order_conf', 'Order confirmation', $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment); $this->currentOrder = intval($order->id); return true; } $this->currentOrder = intval($order->id); return true;
  • 37. We are preparing whole mail, including pdfattachement, even if we are not sending it. Every times you do it, a little kitten dies Non optimised conditions
  • 38.
  • 39. For flux Beezup we are using ObjectModel
  • 40. It works, but we have 17 sql queries / product to collect all data (product, features, attributes, images...)
  • 41. Ok for 100 products. What about 100 000 ?
  • 42. Risky if we had to generate it on-demand
  • 43. Cron prepares output before robot crawls
  • 44. Robot hits cached xmlUse cron to generate cache
  • 45.
  • 46. For static content use mod_gzip / mod_deflate
  • 47. For php files there is simple patch
  • 48.
  • 49.
  • 50. Use Cache (mod_expires, Etags) for static content such as imagesyou can do it in htacces or httpd.conf ExpiresActiveOn ExpiresDefault"access plus 15 days“ ExpiresByTypeimage/gif A2592000 Network
  • 51.
  • 52. Jquery isn't always fastest. Search native methods.
  • 53. Avoid passing HTML / XML as AJAX result. Use JSON instead of. You can reduce amount of data by magnitude of 75% (which if of course faster. Which is of course better). Client-sidestuff
  • 55. SQL Injection CSRF XSS Pathtranversal … Different types of attacks
  • 56. Allowsyou to interactwith the database Sanitize all your variables before use in SQL requests!<?php ...... $order_detail = Db::getInstance()->ExecuteS(' SELECT * FROM .'_DB_PREFIX_.'order_detail WHERE id_order='.(int)$_GET['id_order'] AND payment=apos;'.pSQL($_GET['payment']).'apos;'); SQL Injection
  • 57. Exploit the site's trust in your identity Use tokens Requiring authentication in GET and POST parameters index.php?tab=AdminOrders&token=e84b3fda0b04b922b3bc27b08d4fe136 CSRF
  • 58. Inject HTML code in the page Sanitize all your variables before output! <input type="text" name="lastname" value="{$smarty.post.lastname|htmlentities}" /> preg_replace('/.*script/ui', '', $_POST['lastname']); preg_replace('/.*onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave/ui', '', $_POST['lastname']); ... XSS
  • 59. Access to unauthorized datas Sanitize all your variables before load files! Check the extention of the file include (dirname(__FILE__).'/mails/'. preg_replace(‘/{2,}/', '.', Tools::getValue('mail')).'html'); Path transversal