2023-05-17 15:24:45 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\extension;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\Extension;
|
2023-12-10 18:27:52 +08:00
|
|
|
use SPC\exception\RuntimeException;
|
|
|
|
|
use SPC\exception\WrongUsageException;
|
2024-09-05 00:00:36 +08:00
|
|
|
use SPC\store\SourcePatcher;
|
2023-05-17 15:24:45 +08:00
|
|
|
use SPC\util\CustomExt;
|
|
|
|
|
|
|
|
|
|
#[CustomExt('opcache')]
|
|
|
|
|
class opcache extends Extension
|
|
|
|
|
{
|
2023-12-10 18:27:52 +08:00
|
|
|
/**
|
|
|
|
|
* @throws WrongUsageException
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
*/
|
2024-05-16 13:01:11 +08:00
|
|
|
public function validate(): void
|
2023-12-10 18:27:52 +08:00
|
|
|
{
|
2024-05-21 14:56:54 +08:00
|
|
|
if ($this->builder->getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') {
|
2023-12-10 18:27:52 +08:00
|
|
|
throw new WrongUsageException('Statically compiled PHP with Zend Opcache only available for PHP >= 8.0 !');
|
|
|
|
|
}
|
2024-05-16 13:01:11 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-05 00:00:36 +08:00
|
|
|
public function patchBeforeBuildconf(): bool
|
|
|
|
|
{
|
2025-07-29 10:59:36 +08:00
|
|
|
$version = $this->builder->getPHPVersion();
|
2024-09-05 00:00:36 +08:00
|
|
|
if (file_exists(SOURCE_PATH . '/php-src/.opcache_patched')) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// if 8.2.0 <= PHP_VERSION < 8.2.23, we need to patch from legacy patch file
|
2025-07-29 10:59:36 +08:00
|
|
|
if (version_compare($version, '8.2.0', '>=') && version_compare($version, '8.2.23', '<')) {
|
2024-09-05 00:00:36 +08:00
|
|
|
SourcePatcher::patchFile('spc_fix_static_opcache_before_80222.patch', SOURCE_PATH . '/php-src');
|
|
|
|
|
}
|
|
|
|
|
// if 8.3.0 <= PHP_VERSION < 8.3.11, we need to patch from legacy patch file
|
2025-07-29 10:59:36 +08:00
|
|
|
elseif (version_compare($version, '8.3.0', '>=') && version_compare($version, '8.3.11', '<')) {
|
2024-09-05 00:00:36 +08:00
|
|
|
SourcePatcher::patchFile('spc_fix_static_opcache_before_80310.patch', SOURCE_PATH . '/php-src');
|
2025-07-29 10:59:36 +08:00
|
|
|
}
|
|
|
|
|
// if 8.3.12 <= PHP_VERSION < 8.5.0-dev, we need to patch from legacy patch file
|
|
|
|
|
elseif (version_compare($version, '8.5.0-dev', '<')) {
|
2024-09-05 00:00:36 +08:00
|
|
|
SourcePatcher::patchMicro(items: ['static_opcache']);
|
|
|
|
|
}
|
2025-07-29 10:59:36 +08:00
|
|
|
// PHP 8.5.0-dev and later supports static opcache without patching
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-09-05 00:00:36 +08:00
|
|
|
return file_put_contents(SOURCE_PATH . '/php-src/.opcache_patched', '1') !== false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-27 11:12:19 +07:00
|
|
|
public function getUnixConfigureArg(bool $shared = false): string
|
2024-05-16 13:01:11 +08:00
|
|
|
{
|
2025-07-29 10:59:36 +08:00
|
|
|
$version = $this->builder->getPHPVersion();
|
2025-07-29 11:22:58 +08:00
|
|
|
$opcache_jit = !$this->builder->getOption('disable-opcache-jit', false);
|
|
|
|
|
$opcache_jit = $opcache_jit ? '--enable-opcache-jit' : '--disable-opcache-jit';
|
2025-07-29 10:59:36 +08:00
|
|
|
if (version_compare($version, '8.5.0-dev', '<')) {
|
2025-07-29 11:22:58 +08:00
|
|
|
return "--enable-opcache {$opcache_jit}";
|
2025-07-29 10:59:36 +08:00
|
|
|
}
|
2025-07-29 11:22:58 +08:00
|
|
|
return $opcache_jit;
|
2023-12-10 18:27:52 +08:00
|
|
|
}
|
|
|
|
|
|
2023-05-17 15:24:45 +08:00
|
|
|
public function getDistName(): string
|
|
|
|
|
{
|
|
|
|
|
return 'Zend Opcache';
|
|
|
|
|
}
|
|
|
|
|
}
|