Phar, The PHP .exe                          format                           Helgi Þormar Þorbjörnsson                    ...
Who am I?Friday, 27 January 12
Helgi                        Co-founded Orchestra.io                        Work at EngineYard                        PEAR...
What is Phar?Friday, 27 January 12
Phar                          =                        PHP ArchiveFriday, 27 January 12
Similar to JAR                           ... But for PHPFriday, 27 January 12
Phar                        PHP Extension                        Built in / default from 5.3 onwards                      ...
PEAR: PHP_Archive                        Reference implementation                        User Land Code                   ...
Phar unravelledFriday, 27 January 12
Simple yet flexible                           File FormatFriday, 27 January 12
Pack multiple files                             into oneFriday, 27 January 12
PharFriday, 27 January 12
Similar to TarFriday, 27 January 12
The special sauce                          1. Stub                          2. Manifest                          3. File C...
Manifest                        List of Files                        File Permission                        File Compressi...
Compression                               Whole Archive                                  Per file                        Av...
Stub                        Piece of PHP code                           Bootstraping                           AutoloaderF...
Get all the code used in                          this talk and more!                         https://github.com/helgi/pha...
Going more practicalFriday, 27 January 12
Normal IncludeFriday, 27 January 12
Phar IncludeFriday, 27 January 12
Phar works via StreamsFriday, 27 January 12
Streams Usage                        fopen / fwrite / fclose                        file_get_contents                      ...
Friday, 27 January 12
Does not extract to diskFriday, 27 January 12
Works on web and CLIFriday, 27 January 12
Can be ran without the                              extensionFriday, 27 January 12
Why use Phar?Friday, 27 January 12
Full ApplicationsFriday, 27 January 12
CLI Applications                               Pyrus                              PHPUnitFriday, 27 January 12
Web ApplicationsFriday, 27 January 12
Setup Tools                                 go-pear.phar                        PEAR installation in PHP buildsFriday, 27 ...
Supporting CodeFriday, 27 January 12
Plugins                         LithiumFriday, 27 January 12
ThemesFriday, 27 January 12
Libraries                           SilexFriday, 27 January 12
Handy                        Packaging!Friday, 27 January 12
Executable file for                          applications!Friday, 27 January 12
Pros and ConsFriday, 27 January 12
Pros                        Single download with all dependencies                        Run multiple versions in parallel...
Cons                        Incremental updates (no deltas)                        Upgrading is a manual process          ...
StubsFriday, 27 January 12
Bootstrap for pharFriday, 27 January 12
Smallest possible StubFriday, 27 January 12
__HALT_COMPILER() is a minimum requirementFriday, 27 January 12
Not used when phar file                          is used via streamsFriday, 27 January 12
Web PharFriday, 27 January 12
Phar::interceptFileFuncs()                        Phar::mungServer()                        Phar::WebPharFriday, 27 Januar...
CLI PharFriday, 27 January 12
No Phar::WebPhar()                        Simple file include                        Shebang for easy executionFriday, 27 J...
Web and CLI PharFriday, 27 January 12
CLI + AutoloadFriday, 27 January 12
CLI + Autoload      cli.php         a.php        b.phpFriday, 27 January 12
Phar offers a default stubFriday, 27 January 12
Will work for mostFriday, 27 January 12
Extracts to temp dir if                        Phar is not availableFriday, 27 January 12
PerformanceFriday, 27 January 12
Works with APCFriday, 27 January 12
Works on files inside                 the archiveFriday, 27 January 12
Remember, everything                           goes via PHP                         Extract static files to a directory    ...
SecurityFriday, 27 January 12
Phar disallows                        writing by defaultFriday, 27 January 12
Suhosin                    Enabled by default in Debian and UbuntuFriday, 27 January 12
Signatures are used to check the                            integrity of the archiveFriday, 27 January 12
Signature                        Hashes:   OpenSSL                         MD5                         SHA1               ...
Hashes                        By default executable Phar is signed SHA1                        Tar / Zip are not unless sp...
Extra Goodies!Friday, 27 January 12
Phar::mount()                        Mount external files, such as config, into                                   the phar a...
PharData                        Phar archives can be extracted to disk                        Can operate on non-phar gzip...
Useful Tools                        phar-util                         https://github.com/koto/phar-util                   ...
Get all the code used in                          this talk and more!                         https://github.com/helgi/pha...
Come to the winter party tomorrow!                    Beer and food is on me :-)                        And some awesome s...
Questions?                                      @h                            helgi@engineyard.com                        ...
Upcoming SlideShare
Loading in...5
×

Phar, The PHP .exe Format

7,899

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,899
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
36
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Phar, The PHP .exe Format

  1. 1. Phar, The PHP .exe format Helgi Þormar Þorbjörnsson PHP Benelux, 27th of January 2012Friday, 27 January 12
  2. 2. Who am I?Friday, 27 January 12
  3. 3. Helgi Co-founded Orchestra.io Work at EngineYard PEAR Developer From Iceland @h on TwitterFriday, 27 January 12
  4. 4. What is Phar?Friday, 27 January 12
  5. 5. Phar = PHP ArchiveFriday, 27 January 12
  6. 6. Similar to JAR ... But for PHPFriday, 27 January 12
  7. 7. Phar PHP Extension Built in / default from 5.3 onwards More Powerful than PHP_ArchiveFriday, 27 January 12
  8. 8. PEAR: PHP_Archive Reference implementation User Land Code Less Powerful Works on older PHP Not maintained anymoreFriday, 27 January 12
  9. 9. Phar unravelledFriday, 27 January 12
  10. 10. Simple yet flexible File FormatFriday, 27 January 12
  11. 11. Pack multiple files into oneFriday, 27 January 12
  12. 12. PharFriday, 27 January 12
  13. 13. Similar to TarFriday, 27 January 12
  14. 14. The special sauce 1. Stub 2. Manifest 3. File Contents 4. Signature (optional)Friday, 27 January 12
  15. 15. Manifest List of Files File Permission File Compression Meta DataFriday, 27 January 12
  16. 16. Compression Whole Archive Per file Available Compressions gzip, bz2 and zipFriday, 27 January 12
  17. 17. Stub Piece of PHP code Bootstraping AutoloaderFriday, 27 January 12
  18. 18. Get all the code used in this talk and more! https://github.com/helgi/phar-talkFriday, 27 January 12
  19. 19. Going more practicalFriday, 27 January 12
  20. 20. Normal IncludeFriday, 27 January 12
  21. 21. Phar IncludeFriday, 27 January 12
  22. 22. Phar works via StreamsFriday, 27 January 12
  23. 23. Streams Usage fopen / fwrite / fclose file_get_contents opendir / rmdir / mkdir anything that works with streamsFriday, 27 January 12
  24. 24. Friday, 27 January 12
  25. 25. Does not extract to diskFriday, 27 January 12
  26. 26. Works on web and CLIFriday, 27 January 12
  27. 27. Can be ran without the extensionFriday, 27 January 12
  28. 28. Why use Phar?Friday, 27 January 12
  29. 29. Full ApplicationsFriday, 27 January 12
  30. 30. CLI Applications Pyrus PHPUnitFriday, 27 January 12
  31. 31. Web ApplicationsFriday, 27 January 12
  32. 32. Setup Tools go-pear.phar PEAR installation in PHP buildsFriday, 27 January 12
  33. 33. Supporting CodeFriday, 27 January 12
  34. 34. Plugins LithiumFriday, 27 January 12
  35. 35. ThemesFriday, 27 January 12
  36. 36. Libraries SilexFriday, 27 January 12
  37. 37. Handy Packaging!Friday, 27 January 12
  38. 38. Executable file for applications!Friday, 27 January 12
  39. 39. Pros and ConsFriday, 27 January 12
  40. 40. Pros Single download with all dependencies Run multiple versions in parallel Upgrades are easy No unpacking Security against modificationsFriday, 27 January 12
  41. 41. 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 reachFriday, 27 January 12
  42. 42. StubsFriday, 27 January 12
  43. 43. Bootstrap for pharFriday, 27 January 12
  44. 44. Smallest possible StubFriday, 27 January 12
  45. 45. __HALT_COMPILER() is a minimum requirementFriday, 27 January 12
  46. 46. Not used when phar file is used via streamsFriday, 27 January 12
  47. 47. Web PharFriday, 27 January 12
  48. 48. Phar::interceptFileFuncs() Phar::mungServer() Phar::WebPharFriday, 27 January 12
  49. 49. CLI PharFriday, 27 January 12
  50. 50. No Phar::WebPhar() Simple file include Shebang for easy executionFriday, 27 January 12
  51. 51. Web and CLI PharFriday, 27 January 12
  52. 52. CLI + AutoloadFriday, 27 January 12
  53. 53. CLI + Autoload cli.php a.php b.phpFriday, 27 January 12
  54. 54. Phar offers a default stubFriday, 27 January 12
  55. 55. Will work for mostFriday, 27 January 12
  56. 56. Extracts to temp dir if Phar is not availableFriday, 27 January 12
  57. 57. PerformanceFriday, 27 January 12
  58. 58. Works with APCFriday, 27 January 12
  59. 59. Works on files inside the archiveFriday, 27 January 12
  60. 60. Remember, everything goes via PHP Extract static files to a directory and serve from thereFriday, 27 January 12
  61. 61. SecurityFriday, 27 January 12
  62. 62. Phar disallows writing by defaultFriday, 27 January 12
  63. 63. Suhosin Enabled by default in Debian and UbuntuFriday, 27 January 12
  64. 64. Signatures are used to check the integrity of the archiveFriday, 27 January 12
  65. 65. Signature Hashes: OpenSSL MD5 SHA1 SHA256 SHA512Friday, 27 January 12
  66. 66. Hashes By default executable Phar is signed SHA1 Tar / Zip are not unless specifiedFriday, 27 January 12
  67. 67. Extra Goodies!Friday, 27 January 12
  68. 68. Phar::mount() Mount external files, such as config, into the phar archiveFriday, 27 January 12
  69. 69. 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
  70. 70. Useful Tools phar-util https://github.com/koto/phar-util empir http://empir.sourceforge.net/Friday, 27 January 12
  71. 71. Get all the code used in this talk and more! https://github.com/helgi/phar-talkFriday, 27 January 12
  72. 72. Come to the winter party tomorrow! Beer and food is on me :-) And some awesome swag!Friday, 27 January 12
  73. 73. Questions? @h helgi@engineyard.com https://github.com/helgi/phar-talk Joind.in: http://joind.in/4755Friday, 27 January 12
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×