SlideShare une entreprise Scribd logo
1  sur  73
Télécharger pour lire hors ligne
Phar, The PHP .exe
                          format


                           Helgi Þormar Þorbjörnsson
                        PHP Benelux, 27th of January 2012

Friday, 27 January 12
Who am I?



Friday, 27 January 12
Helgi
                        Co-founded Orchestra.io
                        Work at EngineYard
                        PEAR Developer
                        From Iceland
                        @h on Twitter


Friday, 27 January 12
What is Phar?



Friday, 27 January 12
Phar
                          =
                        PHP Archive

Friday, 27 January 12
Similar to JAR

                           ... But for PHP


Friday, 27 January 12
Phar

                        PHP Extension
                        Built in / default from 5.3 onwards
                        More Powerful than PHP_Archive




Friday, 27 January 12
PEAR: PHP_Archive

                        Reference implementation
                        User Land Code
                        Less Powerful
                        Works on older PHP
                        Not maintained anymore



Friday, 27 January 12
Phar unravelled



Friday, 27 January 12
Simple yet flexible
                           File Format


Friday, 27 January 12
Pack multiple files
                             into one


Friday, 27 January 12
Phar




Friday, 27 January 12
Similar to Tar



Friday, 27 January 12
The special sauce
                          1. Stub
                          2. Manifest
                          3. File Contents
                          4. Signature (optional)




Friday, 27 January 12
Manifest
                        List of Files
                        File Permission
                        File Compression
                        Meta Data




Friday, 27 January 12
Compression
                               Whole Archive
                                  Per file


                        Available Compressions

                              gzip, bz2 and zip


Friday, 27 January 12
Stub

                        Piece of PHP code
                           Bootstraping
                           Autoloader




Friday, 27 January 12
Get all the code used in
                          this talk and more!


                         https://github.com/helgi/phar-talk




Friday, 27 January 12
Going more practical



Friday, 27 January 12
Normal Include




Friday, 27 January 12
Phar Include




Friday, 27 January 12
Phar works via Streams




Friday, 27 January 12
Streams Usage

                        fopen / fwrite / fclose
                        file_get_contents
                        opendir / rmdir / mkdir
                        anything that works with streams




Friday, 27 January 12
Friday, 27 January 12
Does not extract to disk




Friday, 27 January 12
Works on web and CLI




Friday, 27 January 12
Can be ran without the
                              extension




Friday, 27 January 12
Why use Phar?



Friday, 27 January 12
Full Applications



Friday, 27 January 12
CLI Applications
                               Pyrus
                              PHPUnit




Friday, 27 January 12
Web Applications



Friday, 27 January 12
Setup Tools
                                 go-pear.phar
                        PEAR installation in PHP builds




Friday, 27 January 12
Supporting Code



Friday, 27 January 12
Plugins

                         Lithium




Friday, 27 January 12
Themes



Friday, 27 January 12
Libraries

                           Silex




Friday, 27 January 12
Handy
                        Packaging!



Friday, 27 January 12
Executable file for
                          applications!




Friday, 27 January 12
Pros and Cons



Friday, 27 January 12
Pros

                        Single download with all dependencies
                        Run multiple versions in parallel
                        Upgrades are easy
                        No unpacking
                        Security against modifications



Friday, 27 January 12
Cons

                        Incremental updates (no deltas)
                        Upgrading is a manual process
                        Web server may need changes
                        Extending the application is harder
                        README / INSTALL become hard to reach



Friday, 27 January 12
Stubs



Friday, 27 January 12
Bootstrap for phar



Friday, 27 January 12
Smallest possible Stub




Friday, 27 January 12
__HALT_COMPILER() is a minimum requirement




Friday, 27 January 12
Not used when phar file
                          is used via streams




Friday, 27 January 12
Web Phar




Friday, 27 January 12
Phar::interceptFileFuncs()
                        Phar::mungServer()
                        Phar::WebPhar




Friday, 27 January 12
CLI Phar




Friday, 27 January 12
No Phar::WebPhar()
                        Simple file include
                        Shebang for easy execution




Friday, 27 January 12
Web and CLI Phar




Friday, 27 January 12
CLI + Autoload




Friday, 27 January 12
CLI + Autoload
      cli.php



         a.php




        b.php


Friday, 27 January 12
Phar offers a default stub




Friday, 27 January 12
Will work for most




Friday, 27 January 12
Extracts to temp dir if
                        Phar is not available




Friday, 27 January 12
Performance



Friday, 27 January 12
Works with APC



Friday, 27 January 12
Works on files inside
                 the archive


Friday, 27 January 12
Remember, everything
                           goes via PHP


                         Extract static files to a directory
                              and serve from there



Friday, 27 January 12
Security



Friday, 27 January 12
Phar disallows
                        writing by default




Friday, 27 January 12
Suhosin

                    Enabled by default in Debian and Ubuntu




Friday, 27 January 12
Signatures are used to check the
                            integrity of the archive




Friday, 27 January 12
Signature
                        Hashes:   OpenSSL
                         MD5
                         SHA1
                         SHA256
                         SHA512




Friday, 27 January 12
Hashes

                        By default executable Phar is signed SHA1
                        Tar / Zip are not unless specified




Friday, 27 January 12
Extra Goodies!



Friday, 27 January 12
Phar::mount()

                        Mount external files, such as config, into
                                   the phar archive




Friday, 27 January 12
PharData

                        Phar archives can be extracted to disk
                        Can operate on non-phar gzip and tar
                        extract and compress archives


                                Like PDO for archives! :-)



Friday, 27 January 12
Useful Tools

                        phar-util
                         https://github.com/koto/phar-util
                        empir
                         http://empir.sourceforge.net/




Friday, 27 January 12
Get all the code used in
                          this talk and more!


                         https://github.com/helgi/phar-talk




Friday, 27 January 12
Come to the winter party tomorrow!
                    Beer and food is on me :-)

                        And some awesome swag!




Friday, 27 January 12
Questions?

                                      @h
                            helgi@engineyard.com

                        https://github.com/helgi/phar-talk


                        Joind.in: http://joind.in/4755
Friday, 27 January 12

Contenu connexe

En vedette

SMS-SMPP-Concepts
SMS-SMPP-ConceptsSMS-SMPP-Concepts
SMS-SMPP-Concepts
Duy Do Phan
 
The state of PHPUnit
The state of PHPUnitThe state of PHPUnit
The state of PHPUnit
Edorian
 

En vedette (18)

Contaminazione della Digital transformation: dalla banca all'assicurazione
Contaminazione della Digital transformation: dalla banca all'assicurazioneContaminazione della Digital transformation: dalla banca all'assicurazione
Contaminazione della Digital transformation: dalla banca all'assicurazione
 
The Angular road from 1.x to 2.0
The Angular road from 1.x to 2.0The Angular road from 1.x to 2.0
The Angular road from 1.x to 2.0
 
Connected Objects are Natural Born Storytellers (LECTURE @NABA, 2015 )
Connected Objects are Natural Born Storytellers (LECTURE @NABA, 2015 )Connected Objects are Natural Born Storytellers (LECTURE @NABA, 2015 )
Connected Objects are Natural Born Storytellers (LECTURE @NABA, 2015 )
 
WTF? Why The Future Is Up To Us.
WTF? Why The Future Is Up To Us.WTF? Why The Future Is Up To Us.
WTF? Why The Future Is Up To Us.
 
Messaging Apps Overview
Messaging Apps OverviewMessaging Apps Overview
Messaging Apps Overview
 
SMPP
SMPPSMPP
SMPP
 
I processi di contrattualizzazione paperless
I processi di contrattualizzazione paperlessI processi di contrattualizzazione paperless
I processi di contrattualizzazione paperless
 
XYZ – OUTPUT – Processi
XYZ – OUTPUT – Processi XYZ – OUTPUT – Processi
XYZ – OUTPUT – Processi
 
SMS-SMPP-Concepts
SMS-SMPP-ConceptsSMS-SMPP-Concepts
SMS-SMPP-Concepts
 
Emotiv EPOC EEG Headset
Emotiv EPOC EEG HeadsetEmotiv EPOC EEG Headset
Emotiv EPOC EEG Headset
 
What's the Future?
What's the Future?What's the Future?
What's the Future?
 
Quattro riflessioni sulla comunicazione contemporanea
Quattro riflessioni sulla comunicazione contemporaneaQuattro riflessioni sulla comunicazione contemporanea
Quattro riflessioni sulla comunicazione contemporanea
 
Avversari, non nemici: come affrontare una campagna elettorale senza trasform...
Avversari, non nemici: come affrontare una campagna elettorale senza trasform...Avversari, non nemici: come affrontare una campagna elettorale senza trasform...
Avversari, non nemici: come affrontare una campagna elettorale senza trasform...
 
Application Starter Kits for Developers - Building with Watson
Application Starter Kits for Developers - Building with WatsonApplication Starter Kits for Developers - Building with Watson
Application Starter Kits for Developers - Building with Watson
 
The state of PHPUnit
The state of PHPUnitThe state of PHPUnit
The state of PHPUnit
 
Startup Metrics for Mobile Pirates #MOAARRR by Edith Yeung / 500 Mobile Colle...
Startup Metrics for Mobile Pirates #MOAARRR by Edith Yeung / 500 Mobile Colle...Startup Metrics for Mobile Pirates #MOAARRR by Edith Yeung / 500 Mobile Colle...
Startup Metrics for Mobile Pirates #MOAARRR by Edith Yeung / 500 Mobile Colle...
 
Gcvi presentation clean
Gcvi presentation   cleanGcvi presentation   clean
Gcvi presentation clean
 
Gcvi presentation clean
Gcvi presentation   cleanGcvi presentation   clean
Gcvi presentation clean
 

Plus de Helgi Þormar Þorbjörnsson

Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009
Helgi Þormar Þorbjörnsson
 
Website releases made easy with the PEAR installer - Barcelona 2008
Website releases made easy with the PEAR installer - Barcelona 2008Website releases made easy with the PEAR installer - Barcelona 2008
Website releases made easy with the PEAR installer - Barcelona 2008
Helgi Þormar Þorbjörnsson
 

Plus de Helgi Þormar Þorbjörnsson (17)

Distribute the workload, PHP Barcelona 2011
Distribute the workload, PHP Barcelona 2011Distribute the workload, PHP Barcelona 2011
Distribute the workload, PHP Barcelona 2011
 
Distribute the workload, PHPTek, Amsterdam, 2011
Distribute the workload, PHPTek, Amsterdam, 2011Distribute the workload, PHPTek, Amsterdam, 2011
Distribute the workload, PHPTek, Amsterdam, 2011
 
Frontend Caching, PHPTek 2011, Chicago
Frontend Caching, PHPTek 2011, ChicagoFrontend Caching, PHPTek 2011, Chicago
Frontend Caching, PHPTek 2011, Chicago
 
Scale like an ant, distribute the workload - DPC, Amsterdam, 2011
Scale like an ant, distribute the workload - DPC, Amsterdam,  2011Scale like an ant, distribute the workload - DPC, Amsterdam,  2011
Scale like an ant, distribute the workload - DPC, Amsterdam, 2011
 
Think like an ant, distribute the workload - PhpDay, Italy, 2011
Think like an ant, distribute the workload - PhpDay, Italy, 2011Think like an ant, distribute the workload - PhpDay, Italy, 2011
Think like an ant, distribute the workload - PhpDay, Italy, 2011
 
Frontend caching - PHP Day, Italy, 2011
Frontend caching - PHP Day, Italy, 2011Frontend caching - PHP Day, Italy, 2011
Frontend caching - PHP Day, Italy, 2011
 
Frontend caching
Frontend cachingFrontend caching
Frontend caching
 
Plant Pyrus in your system - A guide to a plugin system.
Plant Pyrus in your system - A guide to a plugin system.Plant Pyrus in your system - A guide to a plugin system.
Plant Pyrus in your system - A guide to a plugin system.
 
PEAR2 & Pyrus - The look ahead
PEAR2 & Pyrus - The look aheadPEAR2 & Pyrus - The look ahead
PEAR2 & Pyrus - The look ahead
 
Frontend Caching - The "new" frontier
Frontend Caching - The "new" frontierFrontend Caching - The "new" frontier
Frontend Caching - The "new" frontier
 
Caching for Cash, part 4 DPC 2009
Caching for Cash, part 4 DPC 2009Caching for Cash, part 4 DPC 2009
Caching for Cash, part 4 DPC 2009
 
Cashing For Cash, part 1 DPC 2009
Cashing For Cash, part 1 DPC 2009Cashing For Cash, part 1 DPC 2009
Cashing For Cash, part 1 DPC 2009
 
Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009
 
Caching for Cash - Part 4
Caching for Cash - Part 4Caching for Cash - Part 4
Caching for Cash - Part 4
 
Caching for Cash - Part 1
Caching for Cash - Part 1Caching for Cash - Part 1
Caching for Cash - Part 1
 
Coping with Cyber Monday
Coping with Cyber MondayCoping with Cyber Monday
Coping with Cyber Monday
 
Website releases made easy with the PEAR installer - Barcelona 2008
Website releases made easy with the PEAR installer - Barcelona 2008Website releases made easy with the PEAR installer - Barcelona 2008
Website releases made easy with the PEAR installer - Barcelona 2008
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Phar, The PHP .exe Format