Phar, The PHP .exe
format
Helgi Þormar Þorbjörnsson
PHPTek, Chicago, 24th of May 2012
Slide 2
Slide 2 text
Who am I?
Slide 3
Slide 3 text
Co-founded Orchestra.io
Work at EngineYard
PEAR Developer
From Iceland
@h on Twitter
Helgi
Slide 4
Slide 4 text
What is Phar?
Slide 5
Slide 5 text
Phar
=
PHP Archive
Slide 6
Slide 6 text
Similar to JAR
... But for PHP
Slide 7
Slide 7 text
Phar
PHP Extension
Built in / default from 5.3 onwards
More Powerful than PHP_Archive
Slide 8
Slide 8 text
PEAR: PHP_Archive
‣ Reference implementation
‣ User Land Code
‣ Less Powerful
‣ Works on older PHP
‣ Not maintained anymore
Slide 9
Slide 9 text
Phar unravelled
Slide 10
Slide 10 text
Simple yet flexible
File Format
Slide 11
Slide 11 text
Pack multiple files
into one
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
Similar to Tar
Slide 15
Slide 15 text
The special sauce
1. Stub
2. Manifest
3. File Contents
4. Signature (optional)
Slide 16
Slide 16 text
Manifest
List of Files
File Permission
File Compression
Meta Data
Slide 17
Slide 17 text
Compression
Whole Archive
Per file
gzip, bz2 and zip
Available Compressions
Slide 18
Slide 18 text
Stub
Piece of PHP code:
Bootstraping
Autoloader
Slide 19
Slide 19 text
Gotchas
apc.enable_cli = On
detect_unicode = On
Produces ??? ??? ???
Slide 20
Slide 20 text
Get all the code used in
this talk and more!
github.com/helgi/phar-talk
Slide 21
Slide 21 text
Going more practical
Slide 22
Slide 22 text
Normal Include
Slide 23
Slide 23 text
Phar Include
Slide 24
Slide 24 text
Phar works via Streams
Slide 25
Slide 25 text
Streams Usage
fopen / fwrite / fclose
file_get_contents
opendir / rmdir / mkdir
anything that works with streams
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
Does not extract to disk
Slide 28
Slide 28 text
Works on web and CLI
Slide 29
Slide 29 text
Can be ran without the
extension
Slide 30
Slide 30 text
Bit of autoload
magic
Slide 31
Slide 31 text
Slide 32
Slide 32 text
a.php
b.php
Slide 33
Slide 33 text
Slide 34
Slide 34 text
Gotchas
apc.enable_cli = On
detect_unicode = On
Produces ??? ??? ???
Slide 35
Slide 35 text
Why use Phar?
Slide 36
Slide 36 text
Full Applications
Slide 37
Slide 37 text
CLI Applications
Pyrus
PHPUnit
Composer
Slide 38
Slide 38 text
Web Applications
Slide 39
Slide 39 text
go-pear.phar
PEAR installation in PHP builds
Setup Tools
Slide 40
Slide 40 text
Supporting Code
Slide 41
Slide 41 text
Plugins
Lithium
Slide 42
Slide 42 text
Themes
Slide 43
Slide 43 text
Silex
Libraries
Slide 44
Slide 44 text
Handy
Packaging!
Slide 45
Slide 45 text
Executable file for
applications!
Slide 46
Slide 46 text
Pros and Cons
Slide 47
Slide 47 text
Pros
Single download with all dependencies
Run multiple versions in parallel
Upgrades are easy
No unpacking
Security against modifications
Slide 48
Slide 48 text
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