Skip to content

Commit db73a82

Browse files
committed
README: Add Pitfalls section
1 parent f02d93b commit db73a82

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PHP Code compiler - Phar executable compiling utility
1717
- [Install](#install)
1818
- [Requirements](#requirements)
1919
- [Quick install](#quick-install)
20+
- [Pitfalls](#pitfalls)
2021
- [License](#license)
2122

2223
## Usage
@@ -133,6 +134,59 @@ _Add execution permissions to the binary_
133134
chmod +x ${BINDIR}/phpcc
134135
```
135136

137+
## Pitfalls
138+
139+
Here is a (non-exhaustive) list of the most common mistakes related to PHAR compiling.
140+
141+
### Shebang line in main script
142+
143+
Since the main (entrypoint) script will be **included** in the PHAR stub, it must not contain any shebang line, otherwise this line will be treated as text and printed to standard output when invoking the compiled PHAR.
144+
145+
_Example: Invoking a version of `phpcc` compiled with a shebang line in `bin/compile.php`_
146+
147+
```
148+
$ bin/phpcc --version
149+
#!/usr/bin/env php
150+
PHP Code Compiler version 1.3.0-dev
151+
```
152+
153+
### Local versus compiled files
154+
155+
Let's consider the following tree (all files required by the app)
156+
157+
```
158+
bin/acme.php
159+
src/Command/Acme.php
160+
src/Command/SomeClass.php
161+
lib/Ufo.php
162+
```
163+
164+
Compile it (Oops... one Unknown File Object has not been included)
165+
166+
```
167+
phpcc -e bin/acme.php -f bin/acme.php -d src/ -o bin/acme
168+
```
169+
170+
Guess what ?
171+
172+
If the `bin/acme` compiled archive stays in its place, it won't fail, because `lib/Ufo.php` can still be found from its point of view.
173+
174+
### Size too big
175+
176+
Many projects include some dev libraries, for unit test, local data seeding or code inspection.
177+
178+
Fact is, some of those libs have **A LOT** of dependencies... Hence the `vendor` directory, which is usually included in the archive is really **HUGE**.
179+
180+
Q: How do we remediate then ?
181+
182+
A: Before compiling, we ensure the `vendor` directory does not contains any dev library:
183+
184+
```
185+
composer install --no-dev
186+
phpcc -e bin/acme.php -f bin/acme.php -d src/:php -d vendor:php -d vendor:yaml -o bin/acme
187+
```
188+
189+
136190
## License
137191

138192
Licensed under the [MIT License](LICENSE).

0 commit comments

Comments
 (0)