Packaging with phar

phar is a packaging file similar to JAR in PHP. You can use phar to package your webman project into a single phar file for easier deployment.

Special thanks to fuzqing for the PR.

Note
You need to disable the phar configuration option in php.ini, that is, set phar.readonly = 0.

Install Command Line Tool

composer require webman/console

Packaging

Run the command php webman build:phar in the root directory of the webman project. This will generate a webman.phar file in the build directory.

The packaging-related configuration is in config/plugin/webman/console/app.php.

Start and Stop Commands

Start
php webman.phar start or php webman.phar start -d

Stop
php webman.phar stop

Check Status
php webman.phar status

Check Connection Status
php webman.phar connections

Restart
php webman.phar restart or php webman.phar restart -d

Explanation

  • The packaged project does not support reload; updating code requires a restart.

  • To avoid the packaged file size being too large and occupying too much memory, you can set the exclude_pattern and exclude_files options in config/plugin/webman/console/app.php to exclude unnecessary files.

  • After running webman.phar, a runtime directory will be generated in the directory where webman.phar is located, used to store logs and other temporary files.

  • If your project uses an .env file, make sure to place the .env file in the directory where webman.phar is located.

  • Never store user-uploaded files inside the phar package, as operating on user-uploaded files with the phar:// protocol is very dangerous (due to phar deserialization vulnerabilities). User-uploaded files must be stored separately on disk outside the phar package, as described below.

  • If your business requires uploading files to the public directory, you need to separate the public directory and place it in the directory where webman.phar is located. In this case, you need to configure config/app.php.

    'public_path' => base_path(false) . DIRECTORY_SEPARATOR . 'public',

    The business can use the helper function public_path($relative_file_path) to find the actual location of the public directory.

  • Note that webman.phar does not support custom process startup on Windows.