Open pdvnl opened 1 year ago
@pdvnl could you check if you have the zlib extension? Your error is really weird. I cannot reproduce it and also the whole pipeline would have completely failed
$ php -r 'phpinfo();' | grep -i zlib
Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar
Registered Stream Filters => zlib.*, string.rot13, string.toupper, string.tolower, convert.*, consumed, dechunk, bzip2.*, convert.iconv.*
ZLib Version => 1.2.7
zlib
ZLib Support => enabled
Stream Wrapper => compress.zlib://
Stream Filter => zlib.inflate, zlib.deflate
zlib.output_compression => Off => Off
zlib.output_compression_level => -1 => -1
zlib.output_handler => no value => no value
Zlib => Rasmus Lerdorf, Stefan Roehrich, Zeev Suraski, Jade Nicoletti, Michael Wallner
Does the issue still appears with the latest version?
I think I found the issue, the offending code is:
enum CompressionAlgorithm : int
{
case GZ = Phar::GZ;
case BZ2 = Phar::BZ2;
case NONE = Phar::NONE;
}
And this happens when one of the extension does not exist hence Phar::GZ
, for example, result in an invalid value.
Investigating this some more, I cannot reproduce.
Having the following PHP script:
<?php // bin/my-script.php
require __DIR__.'/../vendor/autoload.php';
foreach (\KevinGH\Box\Phar\CompressionAlgorithm::cases() as $case) {
echo $case->name.': '.$case->value.PHP_EOL;
}
I get:
$ docker run --interactive --platform linux/amd64 --rm --workdir=/opt/box --volume="$(pwd)":/opt/box php:8.2-cli php bin/my-script.php
GZ: 4096
BZ2: 8192
NONE: 0
Although:
$ docker run --interactive --platform linux/amd64 --rm --workdir=/opt/box --volume="$(pwd)":/opt/box php:8.2-cli php -r 'var_dump(extension_loaded("bz2"));'
bool(false)
So not having zlib or bz2 loaded should not compromise the usage of CompressionAlgorithm
.
Then if I try to compress a PHAR with bz2 without the extension loaded I get:
? Compressing with the algorithm "BZ2"
[ERROR] Cannot compress the PHAR with the compression algorithm "BZ2": the
extension "bz2" is required but appear to not be loaded
So I am really at a loss as to what the issue is. Unfortunately without more details I cannot help in any way so I will close this for now and re-open if more information is provided.
On 2023-11-08, at 09:24:27, Théo FIDRY @.***> wrote:
Does the issue still appears with the latest version?
— Reply to this email directly, view it on GitHub https://github.com/box-project/box/issues/989#issuecomment-1801304737, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMAUO36QKUTBX22HUF4XBDYDM6TXAVCNFSM6AAAAAAW6MOLQ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBRGMYDINZTG4. You are receiving this because you were mentioned.
Box version @.*** 2023-11-04 17:57:48 UTC - seems OK
I got the same error when running box.phar this way:
# Does not compile
php -d phar.readonly="Off" box.phar compile
After some web searches, I found this issue, which made me think about another match in the web with title "The influence of opcache on the behavior of enum cases". I then tried:
# Compiles correctly
php -d phar.readonly="Off" -d opcache.enable="Off" box.phar compile
Which allowed the compilation to proceed. Finally, I also noticed that the simplest form also works fine:
# Compiles correctly
php box.phar compile
$ ./box.phar -v ... Box version 4.5.1@1e10a1e 2023-11-04 17:57:48 UTC $ php -v PHP 8.1.26 (cli) (built: Nov 24 2023 13:12:14) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.26, Copyright (c) Zend Technologies with Zend OPcache v8.1.26, Copyright (c), by Zend Technologies $ php -m [PHP Modules] apcu bcmath bz2 calendar Core ctype curl date dom exif FFI fileinfo filter ftp gd gettext hash iconv igbinary imagick intl json ldap libxml mbstring memcached msgpack mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_pgsql pdo_sqlite pgsql Phar posix readline redis Reflection session shmop SimpleXML soap sockets sodium SPL sqlite3 standard sysvmsg sysvsem sysvshm tokenizer uploadprogress xml xmlreader xmlrpc xmlwriter xsl Zend OPcache zip zlib [Zend Modules] Zend OPcache
Ha ok this is quite helpful. Re-opening this as it likely means:
Which allowed the compilation to proceed. Finally, I also noticed that the simplest form also works fine:
One idea of Box was that you don't need to worry about setting phar.readonly
, Box will take care of it, you can see more info with the debug output -vvv
Bug report
box.json
```json { "output": "bin/tvinfo", "check-requirements": false, "compression": "GZ" } ```Output
```bash $ box.phar compile > output Box version 4.3.8@5534406 2023-03-17 08:56:09 UTC // Loading the configuration file "/home/paul/develop/tvinfo/box.json". PHP Fatal error: Enum case value must be compile-time evaluatable in phar:///usr/local/bin/box.phar/src/Phar/CompressionAlgorithm.php on line 11 ```