Skip to content

Commit 53c0fb3

Browse files
committed
README: Add Pitfalls section
1 parent 541c737 commit 53c0fb3

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
@@ -134,6 +135,59 @@ _Add execution permissions to the binary_
134135
chmod +x ${BINDIR}/phpcc
135136
```
136137

138+
## Pitfalls
139+
140+
Here is a (non-exhaustive) list of the most common mistakes related to PHAR compiling.
141+
142+
### Shebang line in main script
143+
144+
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.
145+
146+
_Example: Invoking a version of `phpcc` compiled with a shebang line in `bin/compile.php`_
147+
148+
```
149+
$ bin/phpcc --version
150+
#!/usr/bin/env php
151+
PHP Code Compiler version 1.3.0-dev
152+
```
153+
154+
### Local versus compiled files
155+
156+
Let's consider the following tree (all files required by the app)
157+
158+
```
159+
bin/acme.php
160+
src/Command/Acme.php
161+
src/Command/SomeClass.php
162+
lib/Ufo.php
163+
```
164+
165+
Compile it (Oops... one Unknown File Object has not been included)
166+
167+
```
168+
phpcc -e bin/acme.php -f bin/acme.php -d src/ -o bin/acme
169+
```
170+
171+
Guess what ?
172+
173+
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.
174+
175+
### Size too big
176+
177+
Many projects include some dev libraries, for unit test, local data seeding or code inspection.
178+
179+
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**.
180+
181+
Q: How do we remediate then ?
182+
183+
A: Before compiling, we ensure the `vendor` directory does not contains any dev library:
184+
185+
```
186+
composer install --no-dev
187+
phpcc -e bin/acme.php -f bin/acme.php -d src/:php -d vendor:php -d vendor:yaml -o bin/acme
188+
```
189+
190+
137191
## License
138192

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

0 commit comments

Comments
 (0)