Skip to content

Commit

Permalink
README: Add Pitfalls section
Browse files Browse the repository at this point in the history
  • Loading branch information
yannoff authored Apr 25, 2024
1 parent 39e35aa commit 72f56b6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PHP Code compiler - Phar executable compiling utility
- [Install](#install)
- [Requirements](#requirements)
- [Quick install](#quick-install)
- [Pitfalls](#pitfalls)
- [License](#license)

## Usage
Expand Down Expand Up @@ -132,6 +133,47 @@ _Add execution permissions to the binary_
chmod +x ${BINDIR}/phpcc
```

## Pitfalls

Here is a (non-exhaustive) list of the most common mistakes related to PHAR compiling.

### Local versus compiled files

Let's consider the following tree (all files required by the app)

```
bin/acme.php
src/Command/Acme.php
src/Command/SomeClass.php
lib/Ufo.php
```

Compile it (Oops... one Unknown File Object has not been included)

```
phpcc -e bin/acme.php -f bin/acme.php -d src/ -o bin/acme
```

Guess what ?

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.

### Size too big

Many projects include some dev libraries, for unit test, local data seeding or code inspection.

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**.

Q: How do we remediate then ?

A: Before compiling, we ensure the `vendor` directory does not contains any dev library:

```
composer install --no-dev
phpcc -e bin/acme.php -f bin/acme.php -d src/:php -d vendor:php -d vendor:yaml -o bin/acme
```


## License

Licensed under the [MIT License](LICENSE).

0 comments on commit 72f56b6

Please sign in to comment.