appstract / laravel-opcache

Laravel Package for OPcache
MIT License
1.33k stars 118 forks source link

Cannot pass symfony/polyfill-intl-idn under PHP 7.4 #122

Open wilbur-yu opened 3 years ago

wilbur-yu commented 3 years ago

php version: 7.4.14

php artisan opcache:compile --force=true
PHP Parse error:  syntax error, unexpected '|', expecting '{' in /Users/wilbur.yu/MyCode/Work/qingyan/vendor/symfony/polyfill-intl-normalizer/bootstrap80.php on line 18

Parse error: syntax error, unexpected '|', expecting '{' in /Users/wilbur.yu/MyCode/Work/qingyan/vendor/symfony/polyfill-intl-normalizer/bootstrap80.php on line 18
[1]    86000 segmentation fault  php artisan opcache:compile --force=true
lorenzocattaneo commented 3 years ago

This seems to happen at https://github.com/appstract/laravel-opcache/blob/d2ce88cddda6af54c14d1f9ceaaf94b54f38f9d3/src/OpcacheClass.php#L70

because polyfill files that require php 8 syntax are being parsed.

For now I've simply run php artisan vendor:publish --provider="Appstract\Opcache\OpcacheServiceProvider" --tag="config" to publish the config file and added the following to exclude:

'exclude' => [
        ...
        ...
        'symfony/polyfill-ctype',
        'symfony/polyfill-iconv',
        'symfony/polyfill-intl-grapheme',
        'symfony/polyfill-intl-idn',
        'symfony/polyfill-intl-normalizer',
        'symfony/polyfill-mbstring',
        'symfony/polyfill-php80'
    ],

Not a definitive solution but for now it works!

jonathan-bird commented 3 years ago

Any updates soon @ovanschie ? :)

AEmad01 commented 3 years ago

The easy but not very viable solution is use php 8.

stevegrunwell commented 3 years ago

I've spent some time digging into this today, and this appears to impact anyone running on PHP 7.x (7.4, in my case):

When iterating over the found files, opcache_compile_file() trips up on the bootstrap80.php files included within the various symfony/polyfill-* packages, as they use PHP 8.x-specific syntax (the polyfill packages themselves are a dependency of swiftmailer/swiftmailer, which is itself a dependency of laravel/framework).

Normally this wouldn't be a problem, as the Symfony packages only load these files when running on PHP 8.x. However, the list of files doesn't know about this, so we attempt to inject PHP 8.x syntax into a PHP 7.x OPcache and everything goes sideways.

The solution @lorenzocattaneo works as a short-term fix, but ultimately it's excluding everything in those symfony/polyfill-* packages from getting pre-loaded. @wojo1206's work in #125 would let us target specific files (as opposed to whole directories), which would be beneficial, but ultimately some better error handling within OpcacheClass::compile() is needed to prevent issues like this from breaking the whole process.