Skip to content

Commit fe48cd9

Browse files
committed
README: Add Pitfalls section
1 parent 39e35aa commit fe48cd9

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

+54
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
@@ -132,6 +133,59 @@ _Add execution permissions to the binary_
132133
chmod +x ${BINDIR}/phpcc
133134
```
134135

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

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

0 commit comments

Comments
 (0)