Search code examples
phpcomposer-php

PHP: package dependencies in a single file


I'm developing a small php app that should be distributed as a single php file, which is the best way to manage external dependencies?

What if I want to include an external library? How can I package all I need in a single file?


Solution

  • Using a Phar file is the best option.

    Usually .phar files are executed from a command line but they can also be interpreted by web servers.

    You have to configure your server to make sure it manages the .phar extension as a php file. If you can't do that you can use a simple .php file that includes the .phar via a regular include('file.phar');.