bcgen icon indicating copy to clipboard operation
bcgen copied to clipboard

Running from inside PHAR ?

Open henrywood opened this issue 5 years ago • 2 comments

I am trying to get bcgen to work with PHAR files. I have added the compiled PHP files to the PHAR file (using their PHP extension within the PHAR file)

The stub of the PHP archive is:

#!/usr/bin/env php <?php Phar::mapPhar( 'app.phar' ); set_include_path( 'phar://app.phar' . PATH_SEPARATOR.';.'); require('phar://' . __FILE__ . '/app.php'); __HALT_COMPILER(); ?>`

The file app.php is in the root of the PHAR archive and is the version compiled by bcgen.

When I run the phar (on the commandline), all I get is some gibberish output (to STDOUT) and the process exits with exitcode 130 ?

My understanding is that bcgen extension will inspect the file which is included/required (ie. app.php) and then - if it is bytecode - then simply execute the bytecode - If it is not, then it will parse the included file normally ?

However it seems that what actually happens, is that the header of the PHAR file itself is checked and since that is obviously not a BCGEN header, processing is aborted. If we could skip this check when running from a PHAR archive (from the commandline or when the PHAR is included within some other PHP file) and in this scenario only "react" to include/require/autoloading statements (ie. check if a file that is about to be included is bytecode or not - if it is, then run it - If it is not then compile it first and then run the resulting bytecode), then - in my humble opinion - we would have a way of adding minimal protection to PHAR files - useful when redistributing PHARs (since such a PHAR archive would then simply contain a number of files that are bytecode - except for the stub of course...) and that would - I think - make PHAR files even cooler and provide a most sought-after feature.

Please let me know what you think.

Thanks for your efforts for providing bcgen.

henrywood avatar Dec 05 '18 21:12 henrywood

@henrywood It might be that I have accidently removed the support for PHAR files. Maybe you can study the OPcache code to see what is missing.

Personally I am about to abandon this project. See here: https://github.com/nanosonde/bcgen/issues/9#issuecomment-451935549

nanosonde avatar Jan 07 '19 13:01 nanosonde

@nanosonde Thanks for getting back to me ! I'll try to propose the change/idea to @vjardin then !

Also, thank you for your work on BCGen !

henrywood avatar Jan 11 '19 00:01 henrywood