SlideShare una empresa de Scribd logo
1 de 49
Descargar para leer sin conexión
The Why and How of moving to PHP 5.4/5.5
Questions during the talk ?
Ask at http://wpc13.cnf.io
Who am I ?
Wim Godden (@wimgtr)
Founder of Cu.be Solutions (http://cu.be)
Open Source developer since 1997
OpenX, PHPCompatibility, Nginx SCL, ...
Speaker at PHP and Open Source conferences
Why vs How
Part 1 : why upgrade ?
Bad reasons :
It's cool to have the latest version
Annoy sysadmins
Oh cool, a new toy !
Part 2 : how to upgrade ?
The nightmare of compatibility
The joy of automation
No miracles here !
Show of hands
3 / 4
5.0
5.1
5.2
5.3
5.4
5.5
6.0 (just kidding)
The numbers
W3Techs (http://w3techs.com/technologies/details/pl-php/all/all)
Now May 2013
PHP 4 : 2.9% 2.7%
PHP 5 : 97.1% 97.3%
5.0 : 0.1% 0.1%
5.1 : 2.2% 2.6%
5.2 : 40.2% 43.5%
5.3 : 51.7% 49.7%
5.4 : 5.7% 4.1%
5.5 : 0.1 % < 0.1%
5.6 : < 0.1%
5.3 quick recap
Namespaces ()
Late static binding
Closures
Better garbage collection
Goto
Mysqlnd
Performance gain
5.3 – people are not even using it !
40.2% still on PHP 5.2
No :
Symfony 2
Zend Framework 2
Other frameworks that need namespaces
Problematic for developers
PHP 5.4/5.5 – what's changed ?
New features
Performance and memory usage
Improved consistency
Some things removed
New things – short array syntax (5.4)
$yourItems = array('a', 'b', 'c', 'd');
$yourItems = ['a', 'b', 'c', 'd'];
$yourItems = ['a' => 5, 'b' => 3];
New things – function array dereferencing (5.4)
function getCars()
{
return array(
'Mini',
'Smart',
'Volvo',
'BMW'
);
}
$cars = getCars();
echo $cars[1];
function getCars()
{
return [
'Mini',
'Smart',
'Volvo',
'BMW'
];
}
echo getCars()[1];
New things – Traits
Reuse methods across classes
Classes have no common parent
Traits - example
Log output : abcd
trait Logger
{
public function log($data) {
echo "Log output : " . $data;
}
}
class SomeClass {
use Logger;
}
$someObject = new SomeClass();
$someObject->log('abcd');
Traits - example
class SomeClass {
public function log($data) {
echo "Log output : " . $data;
}
}
$someObject = new SomeClass();
$someObject->log('abcd');
Traits – careful !
trait Logger {
private $foo;
}
class SomeClass {
private $foo;
use Logger;
}
will throw E_STRICT !
New things – Webserver (5.4)
Built-in webserver
Development only !
Handles requests sequentially
Ideal for quick testing
Ideal for unit testing of webservices
Webserver – how to
/var/www/php54test/html> php -S localhost:8000
PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013
Listening on http://localhost:8000
Document root is /var/www/php54test/html
Press Ctrl-C to quit.
/var/www/php54test/html> php -S localhost:8000 -t /var/www/other-path/html
PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013
Listening on http://localhost:8000
Document root is /var/www/other-path/html
Press Ctrl-C to quit.
/var/www/php54test/html> php -S localhost:8000 bootstrap.php
PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013
Listening on http://localhost:8000
Document root is /var/www/php54test/html
Press Ctrl-C to quit.
New things – SessionHandler (5.4)
New session handling class
Groups all methods for session handling :
close()
destroy()
gc()
open()
read()
write()
SessionHandler
class MySessionHandler extends SessionHandler
{
public function read($session_id)
{
// Get the session data
}
public function write($session_id, $session_data)
{
// Set the session data
}
...
}
$handler = new MySessionHandler();
session_set_save_handler($handler, true);
session_start();
New things – more session stuff (5.4)
File upload extension
→ file upload registers in session
→ readable through AJAX calls
New function session_status()
Return values : PHP_SESSION_ACTIVE / PHP_SESSION_NONE
New things – Generators (5.5)
Simple way of implementing iterators
Simply put : foreach over a function
Say what ?
Generators - example
<?php
function returnAsciiTable($start, $end) {
for ($i = $start; $i <= $end; $i++) {
yield $i => chr($i);
}
}
foreach (returnAsciiTable(97, 122) as $key => $value) {
echo $key . " - " . $value . "n";
}
Output :
97 - a
98 - b
99 - c
100 - d
101 - e
102 - f
103 - g
104 - h
105 - i
106 - j
107 - k
108 - l
109 - m
110 - n
111 - o
112 - p
113 - q
114 - r
115 - s
116 - t
117 - u
118 - v
119 - w
120 - x
121 - y
122 - z
Finally : finally (5.5)
Exception handling
Until now : try {} catch() {}
Now :
<?php
try {
doSomething();
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "n";
} finally {
echo "We're always going here !";
}
Password hashing (5.5)
To create :
$hash = password_hash($password, PASSWORD_DEFAULT);
To verify :
password_verify($password, $hash);
Currently only supports Blowfish
Also has password_needs_rehash() → check if hash was strong enough
Zend Optimizer+ (5.5)
Name in PHP 5.5 : OPcache
Opcode cache (like APC, Xcache, ...)
APC users : no userland (variable) caching in OPcache
→ Use APCu
Also new
New cURL bits and pieces
Lists in foreach statements
Empty() function accepts expressions
New GD bits and pieces
What else is new ?
Binary notation
Decimal : 123
Octal : 0173
Hex : 0x7B
Binary : 0b1111011
Class member access on object instantiation
$fooObj = new Foo();
echo $fooObj->bar();
echo (new Foo)->bar();
New reserved keywords : (5.4)
trait
insteadof
Callable
Other changes
Error handling :
5.3 : Parse error: syntax error, unexpected T_STRING, expecting '{' in index.php on line 1
5.4 : Parse error: syntax error, unexpected 'bar' (T_STRING), expecting '{' in index.php on line 1
Array to string conversion :
5.3 : Array
5.4 : Note: Array to string conversion in test.php on line 8
<?= always works (even with short_tags off)
Default charset = UTF8 (be careful !)
class foo bar
$var = array();
echo $var;
Time to remove !
register_globals (5.4)
magic_quotes (5.4)
safe_mode (5.4)
Removed (5.4) : Still working :
break $var; break 2;
continue $var; continue 3;
session_register() php_logo_guid()
session_unregister() php_egg_logo_guid()
session_is_registered() php_real_logo_guid()
→ use $_SESSION zend_logo_guid()
(5.4) (5.5)
More stuff removed
Timezone guessing → date.timezone in php.ini (5.4)
sqlite extension → use sqlite3 (5.4)
Windows XP and 2003 support (5.5)
Performance and memory usage
Performance : 10 – 30%
How ?
Core optimizations
New internal caches (functions, constants, …)
Better (un)serialization
Inlining often-used code paths
…
Reduced memory usage : up to 50% !
Big impact on large frameworks
Even bigger impact on codebases such as Drupal
So...
Should you upgrade today ?
Upgrade : yes / no
Yes No
Using removed extensions x
Using removed functions x
Need extra performance / reduced memory x
Really need new feature x
Want to use recent framework x
No unit tests x
No package available (.rpm, .deb, ...) x
Postponing upgrades
End-Of-Life
In the past : we'll see
Now : minor release + 2 = out → EOL
5.5 = OUT → 5.3 = EOL
5.6 = OUT → 5.4 = EOL (next year !)
Critical security patches : 1 year
No bugfixes
Framework support
Developer motivation
So you want to upgrade...
Option 1 : run your unit tests
Option 2 : visit each page (good luck !) + check error_log
Or : record visits, then replay log on test environment
Option 3 : automated static analysis
Back in 2010...
PHP Architect @ Belgian Railways
8 years of legacy code
40+ different developers
40+ projects
Challenge :
migrate all projects from
PHP 5.1.x (on Solaris)
to
PHP 5.3.x (on Linux)
The idea
Automate it
How ? → Use the CI environment
Which tool ? → PHP_CodeSniffer
PHP_CodeSniffer
PEAR package (pear install PHP_CodeSniffer)
Detect coding standard violations
Supports multiple standards
Static analysis tool
→ Runs without executing code
→ Splits code in tokens
Ex. : T_OPEN_CURLY_BRACKET
T_FALSE
T_SEMICOLON
PHP_CodeSniffer
Let's see what it looks like
PHPCompatibility
New PHP_CodeSniffer standard
Only purpose : find compatibility issues
Detects :
Deprecated functions
Deprecated extensions
Deprecated php.ini settings and ini_set() calls
Prohibited function names, class names, …
…
Works for PHP 5.0, 5.1, 5.2, 5.3, 5.4 and 5.5
PHPCompatibility – making it work
Via GIT :
git clone git://github.com/wimg/PHPCompatibility.git PHPCompatibility
Download from Github :
http://github.com/wimg/PHPCompatibility
Install in <pear_dir>/PHP/CodeSniffer/Standards
Run :
phpcs --standard=PHPCompatibility <path>
Important notes
Large directories → can be slow !
Use --extensions=php,phtml
No point scanning .js files
Test PHP 5.5 compatibility → need PHP 5.5 on the system
Static analysis
Doesn't run code
Can not detect every single incompatibility
Provides filename and line number
PHPCompatibility
Let's see what it looks like
The result
Zend Framework 1.7 app
PHP 5.2 : working fine
PHP 5.3 : fail !
function goto()
Conclusion
No 100% detection
But : 95% automation = lots of time saved !
First : PHPCompatibility on local machine
Then : upgrade CI/test environment and run unit tests
Start upgrading !
Questions ?
Questions ?
Contact
Twitter @wimgtr
Web http://techblog.wimgodden.be
Slides http://www.slideshare.net/wimg
E-mail wim.godden@cu.be
Please rate my talk at
http://joind.in/9142
Thanks !
Please rate my talk at
http://joind.in/9142

Más contenido relacionado

La actualidad más candente

PHP 5.6 New and Deprecated Features
PHP 5.6  New and Deprecated FeaturesPHP 5.6  New and Deprecated Features
PHP 5.6 New and Deprecated FeaturesMark Niebergall
 
Nginx and friends - putting a turbo button on your site
Nginx and friends - putting a turbo button on your siteNginx and friends - putting a turbo button on your site
Nginx and friends - putting a turbo button on your siteWim Godden
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 
An introduction to PHP 5.4
An introduction to PHP 5.4An introduction to PHP 5.4
An introduction to PHP 5.4Giovanni Derks
 
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPatrick Allaert
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Joseph Scott
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPAdam Englander
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshopDamien Seguy
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)charsbar
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS charsbar
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLitecharsbar
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13julien pauli
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPANcharsbar
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machinejulien pauli
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and coPierre Joye
 

La actualidad más candente (20)

PHP 5.6 New and Deprecated Features
PHP 5.6  New and Deprecated FeaturesPHP 5.6  New and Deprecated Features
PHP 5.6 New and Deprecated Features
 
Nginx and friends - putting a turbo button on your site
Nginx and friends - putting a turbo button on your siteNginx and friends - putting a turbo button on your site
Nginx and friends - putting a turbo button on your site
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
An introduction to PHP 5.4
An introduction to PHP 5.4An introduction to PHP 5.4
An introduction to PHP 5.4
 
Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6
 
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & Pinba
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHP
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshop
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and co
 

Similar a The why and how of moving to php 5.4/5.5

Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Damien Seguy
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Tips
TipsTips
Tipsmclee
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitJames Fuller
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & ToolsIan Barber
 
Review unknown code with static analysis
Review unknown code with static analysisReview unknown code with static analysis
Review unknown code with static analysisDamien Seguy
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit universityMandakini Kumari
 
Review unknown code with static analysis Zend con 2017
Review unknown code with static analysis  Zend con 2017Review unknown code with static analysis  Zend con 2017
Review unknown code with static analysis Zend con 2017Damien Seguy
 
Php 7 compliance workshop singapore
Php 7 compliance workshop singaporePhp 7 compliance workshop singapore
Php 7 compliance workshop singaporeDamien Seguy
 

Similar a The why and how of moving to php 5.4/5.5 (20)

Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Tips
TipsTips
Tips
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
Review unknown code with static analysis
Review unknown code with static analysisReview unknown code with static analysis
Review unknown code with static analysis
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Php 7 evolution
Php 7 evolutionPhp 7 evolution
Php 7 evolution
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Review unknown code with static analysis Zend con 2017
Review unknown code with static analysis  Zend con 2017Review unknown code with static analysis  Zend con 2017
Review unknown code with static analysis Zend con 2017
 
Php 7 compliance workshop singapore
Php 7 compliance workshop singaporePhp 7 compliance workshop singapore
Php 7 compliance workshop singapore
 

Más de Wim Godden

Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to lifeWim Godden
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8Wim Godden
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7Wim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to lifeWim Godden
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developersWim Godden
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developersWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous phpWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 

Más de Wim Godden (20)

Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to life
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to life
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developers
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developers
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 

Último

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

The why and how of moving to php 5.4/5.5

  • 1. The Why and How of moving to PHP 5.4/5.5
  • 2. Questions during the talk ? Ask at http://wpc13.cnf.io
  • 3. Who am I ? Wim Godden (@wimgtr) Founder of Cu.be Solutions (http://cu.be) Open Source developer since 1997 OpenX, PHPCompatibility, Nginx SCL, ... Speaker at PHP and Open Source conferences
  • 4. Why vs How Part 1 : why upgrade ? Bad reasons : It's cool to have the latest version Annoy sysadmins Oh cool, a new toy ! Part 2 : how to upgrade ? The nightmare of compatibility The joy of automation No miracles here !
  • 5. Show of hands 3 / 4 5.0 5.1 5.2 5.3 5.4 5.5 6.0 (just kidding)
  • 6. The numbers W3Techs (http://w3techs.com/technologies/details/pl-php/all/all) Now May 2013 PHP 4 : 2.9% 2.7% PHP 5 : 97.1% 97.3% 5.0 : 0.1% 0.1% 5.1 : 2.2% 2.6% 5.2 : 40.2% 43.5% 5.3 : 51.7% 49.7% 5.4 : 5.7% 4.1% 5.5 : 0.1 % < 0.1% 5.6 : < 0.1%
  • 7. 5.3 quick recap Namespaces () Late static binding Closures Better garbage collection Goto Mysqlnd Performance gain
  • 8. 5.3 – people are not even using it ! 40.2% still on PHP 5.2 No : Symfony 2 Zend Framework 2 Other frameworks that need namespaces Problematic for developers
  • 9. PHP 5.4/5.5 – what's changed ? New features Performance and memory usage Improved consistency Some things removed
  • 10. New things – short array syntax (5.4) $yourItems = array('a', 'b', 'c', 'd'); $yourItems = ['a', 'b', 'c', 'd']; $yourItems = ['a' => 5, 'b' => 3];
  • 11. New things – function array dereferencing (5.4) function getCars() { return array( 'Mini', 'Smart', 'Volvo', 'BMW' ); } $cars = getCars(); echo $cars[1]; function getCars() { return [ 'Mini', 'Smart', 'Volvo', 'BMW' ]; } echo getCars()[1];
  • 12. New things – Traits Reuse methods across classes Classes have no common parent
  • 13. Traits - example Log output : abcd trait Logger { public function log($data) { echo "Log output : " . $data; } } class SomeClass { use Logger; } $someObject = new SomeClass(); $someObject->log('abcd');
  • 14. Traits - example class SomeClass { public function log($data) { echo "Log output : " . $data; } } $someObject = new SomeClass(); $someObject->log('abcd');
  • 15. Traits – careful ! trait Logger { private $foo; } class SomeClass { private $foo; use Logger; } will throw E_STRICT !
  • 16. New things – Webserver (5.4) Built-in webserver Development only ! Handles requests sequentially Ideal for quick testing Ideal for unit testing of webservices
  • 17. Webserver – how to /var/www/php54test/html> php -S localhost:8000 PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013 Listening on http://localhost:8000 Document root is /var/www/php54test/html Press Ctrl-C to quit. /var/www/php54test/html> php -S localhost:8000 -t /var/www/other-path/html PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013 Listening on http://localhost:8000 Document root is /var/www/other-path/html Press Ctrl-C to quit. /var/www/php54test/html> php -S localhost:8000 bootstrap.php PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013 Listening on http://localhost:8000 Document root is /var/www/php54test/html Press Ctrl-C to quit.
  • 18. New things – SessionHandler (5.4) New session handling class Groups all methods for session handling : close() destroy() gc() open() read() write()
  • 19. SessionHandler class MySessionHandler extends SessionHandler { public function read($session_id) { // Get the session data } public function write($session_id, $session_data) { // Set the session data } ... } $handler = new MySessionHandler(); session_set_save_handler($handler, true); session_start();
  • 20. New things – more session stuff (5.4) File upload extension → file upload registers in session → readable through AJAX calls New function session_status() Return values : PHP_SESSION_ACTIVE / PHP_SESSION_NONE
  • 21. New things – Generators (5.5) Simple way of implementing iterators Simply put : foreach over a function Say what ?
  • 22. Generators - example <?php function returnAsciiTable($start, $end) { for ($i = $start; $i <= $end; $i++) { yield $i => chr($i); } } foreach (returnAsciiTable(97, 122) as $key => $value) { echo $key . " - " . $value . "n"; } Output : 97 - a 98 - b 99 - c 100 - d 101 - e 102 - f 103 - g 104 - h 105 - i 106 - j 107 - k 108 - l 109 - m 110 - n 111 - o 112 - p 113 - q 114 - r 115 - s 116 - t 117 - u 118 - v 119 - w 120 - x 121 - y 122 - z
  • 23. Finally : finally (5.5) Exception handling Until now : try {} catch() {} Now : <?php try { doSomething(); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "n"; } finally { echo "We're always going here !"; }
  • 24. Password hashing (5.5) To create : $hash = password_hash($password, PASSWORD_DEFAULT); To verify : password_verify($password, $hash); Currently only supports Blowfish Also has password_needs_rehash() → check if hash was strong enough
  • 25. Zend Optimizer+ (5.5) Name in PHP 5.5 : OPcache Opcode cache (like APC, Xcache, ...) APC users : no userland (variable) caching in OPcache → Use APCu
  • 26. Also new New cURL bits and pieces Lists in foreach statements Empty() function accepts expressions New GD bits and pieces
  • 27. What else is new ? Binary notation Decimal : 123 Octal : 0173 Hex : 0x7B Binary : 0b1111011 Class member access on object instantiation $fooObj = new Foo(); echo $fooObj->bar(); echo (new Foo)->bar(); New reserved keywords : (5.4) trait insteadof Callable
  • 28. Other changes Error handling : 5.3 : Parse error: syntax error, unexpected T_STRING, expecting '{' in index.php on line 1 5.4 : Parse error: syntax error, unexpected 'bar' (T_STRING), expecting '{' in index.php on line 1 Array to string conversion : 5.3 : Array 5.4 : Note: Array to string conversion in test.php on line 8 <?= always works (even with short_tags off) Default charset = UTF8 (be careful !) class foo bar $var = array(); echo $var;
  • 29. Time to remove ! register_globals (5.4) magic_quotes (5.4) safe_mode (5.4) Removed (5.4) : Still working : break $var; break 2; continue $var; continue 3; session_register() php_logo_guid() session_unregister() php_egg_logo_guid() session_is_registered() php_real_logo_guid() → use $_SESSION zend_logo_guid() (5.4) (5.5)
  • 30. More stuff removed Timezone guessing → date.timezone in php.ini (5.4) sqlite extension → use sqlite3 (5.4) Windows XP and 2003 support (5.5)
  • 31. Performance and memory usage Performance : 10 – 30% How ? Core optimizations New internal caches (functions, constants, …) Better (un)serialization Inlining often-used code paths … Reduced memory usage : up to 50% ! Big impact on large frameworks Even bigger impact on codebases such as Drupal
  • 33. Upgrade : yes / no Yes No Using removed extensions x Using removed functions x Need extra performance / reduced memory x Really need new feature x Want to use recent framework x No unit tests x No package available (.rpm, .deb, ...) x
  • 34. Postponing upgrades End-Of-Life In the past : we'll see Now : minor release + 2 = out → EOL 5.5 = OUT → 5.3 = EOL 5.6 = OUT → 5.4 = EOL (next year !) Critical security patches : 1 year No bugfixes Framework support Developer motivation
  • 35. So you want to upgrade... Option 1 : run your unit tests Option 2 : visit each page (good luck !) + check error_log Or : record visits, then replay log on test environment Option 3 : automated static analysis
  • 36. Back in 2010... PHP Architect @ Belgian Railways 8 years of legacy code 40+ different developers 40+ projects Challenge : migrate all projects from PHP 5.1.x (on Solaris) to PHP 5.3.x (on Linux)
  • 37. The idea Automate it How ? → Use the CI environment Which tool ? → PHP_CodeSniffer
  • 38. PHP_CodeSniffer PEAR package (pear install PHP_CodeSniffer) Detect coding standard violations Supports multiple standards Static analysis tool → Runs without executing code → Splits code in tokens Ex. : T_OPEN_CURLY_BRACKET T_FALSE T_SEMICOLON
  • 40. PHPCompatibility New PHP_CodeSniffer standard Only purpose : find compatibility issues Detects : Deprecated functions Deprecated extensions Deprecated php.ini settings and ini_set() calls Prohibited function names, class names, … … Works for PHP 5.0, 5.1, 5.2, 5.3, 5.4 and 5.5
  • 41. PHPCompatibility – making it work Via GIT : git clone git://github.com/wimg/PHPCompatibility.git PHPCompatibility Download from Github : http://github.com/wimg/PHPCompatibility Install in <pear_dir>/PHP/CodeSniffer/Standards Run : phpcs --standard=PHPCompatibility <path>
  • 42. Important notes Large directories → can be slow ! Use --extensions=php,phtml No point scanning .js files Test PHP 5.5 compatibility → need PHP 5.5 on the system Static analysis Doesn't run code Can not detect every single incompatibility Provides filename and line number
  • 44. The result Zend Framework 1.7 app PHP 5.2 : working fine PHP 5.3 : fail ! function goto()
  • 45. Conclusion No 100% detection But : 95% automation = lots of time saved ! First : PHPCompatibility on local machine Then : upgrade CI/test environment and run unit tests Start upgrading !
  • 48. Contact Twitter @wimgtr Web http://techblog.wimgodden.be Slides http://www.slideshare.net/wimg E-mail wim.godden@cu.be Please rate my talk at http://joind.in/9142
  • 49. Thanks ! Please rate my talk at http://joind.in/9142

Notas del editor

  1. part 2 look at difficulties you might encounter in upgrading. I&apos;ll provide solutions not a magician can&apos;t solve everything ;-)
  2. 5.3.3 = Debian Squeezy = 12% Wait a second... that means people aren&apos;t even on 5.3 ? And there was 3 year gap between the release of 5.2 and 5.3, so 5.3 brought a lot of cool things.