SlideShare uma empresa Scribd logo
1 de 36
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;

Mais conteúdo relacionado

Mais procurados

Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Mark 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 CoffeeScriptStalin 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 MooseMike Whitaker
 
(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
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to ServicesCraig Kerstiens
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With PhpJeremy 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) ThingsMichael Pirnat
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)xSawyer
 
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 ApplicationsFestGroup
 
Getting Hiera and Hiera
Getting Hiera and HieraGetting Hiera and Hiera
Getting Hiera and HieraPuppet
 
Moose Best Practices
Moose Best PracticesMoose Best Practices
Moose Best PracticesAran Deltac
 

Mais procurados (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
 

Semelhante a Good practices for PrestaShop code security and optimization

Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
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 MingRick 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 @ PHPTourWim Godden
 
Everyone loves PHP
Everyone loves PHPEveryone loves PHP
Everyone loves PHPAbhijit 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 CakePHPMariano Iglesias
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: BackendVõ 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 MeetupJonathan Klein
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - GoodiesJerry Emmanuel
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate WorksGoro Fuji
 
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
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4alexsaves
 
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 approachJinal Jhaveri
 
Website Security
Website SecurityWebsite Security
Website SecurityCarlos Z
 
Website Security
Website SecurityWebsite Security
Website SecurityMODxpo
 

Semelhante a 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
 

Mais de 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-commercePrestaShop
 
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-ColissimoPrestaShop
 
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.4PrestaShop
 
Barcamp 3 PrestaShop - Atelier Intégration
Barcamp 3 PrestaShop - Atelier IntégrationBarcamp 3 PrestaShop - Atelier Intégration
Barcamp 3 PrestaShop - Atelier IntégrationPrestaShop
 
Barcamp 3 PrestaShop - Atelier PrestaShop / eBay
Barcamp 3 PrestaShop - Atelier PrestaShop / eBayBarcamp 3 PrestaShop - Atelier PrestaShop / eBay
Barcamp 3 PrestaShop - Atelier PrestaShop / eBayPrestaShop
 
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 commandePrestaShop
 
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 - OuverturePrestaShop
 
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 DepotPrestaShop
 
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 - LocitaPrestaShop
 
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-EcommercePrestaShop
 
Performance et optimisation de PrestaShop
Performance et optimisation de PrestaShopPerformance et optimisation de PrestaShop
Performance et optimisation de PrestaShopPrestaShop
 
Installation & Configuration - PrestaShop
Installation & Configuration - PrestaShopInstallation & Configuration - PrestaShop
Installation & Configuration - PrestaShopPrestaShop
 
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 PrestaShopPrestaShop
 
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 PrestaShopPrestaShop
 
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 PrestaShopPrestaShop
 

Mais de 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
 

Último

7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with CultureSeta Wicaksana
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxpriyanshujha201
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...amitlee9823
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityEric T. Tung
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsP&CO
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageMatteo Carbone
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Serviceritikaroy0888
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...Aggregage
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Delhi Call girls
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Centuryrwgiffor
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxAndy Lambert
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...amitlee9823
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLSeo
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataExhibitors Data
 

Último (20)

7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Service
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptx
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 

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