solariumphp / solarium

PHP Solr client library
Other
933 stars 302 forks source link

Undefined constant Solarium\DEPRECATED_CONSTANT_SOLARIUM_VERSION - php 8.1.8 opcache.preload #1029

Closed ambroisemaupate closed 2 years ago

ambroisemaupate commented 2 years ago

Solarium: 6.2.6 php: 8.1.8


When enabling opcache.preload on a Symfony project, it seems that the following constant is not available anymore:

# src/Client.php
// Workaround to assign a "dynamic" value to Client::VERSION.
define('DEPRECATED_CONSTANT_SOLARIUM_VERSION', InstalledVersions::getPrettyVersion('solarium/solarium'));

Description

Error: Undefined constant "Solarium\DEPRECATED_CONSTANT_SOLARIUM_VERSION"
#21 /var/cache/prod/ContainerZnsuwM6/Client_2fb41ef.php(326): ReflectionClass::newInstanceWithoutConstructor
#20 /var/cache/prod/ContainerZnsuwM6/Client_2fb41ef.php(326): ContainerZnsuwM6\Client_2fb41ef::staticProxyConstructor
#19 /var/cache/prod/ContainerZnsuwM6/getRoadizCore_Solr_ClientService.php(28): ContainerZnsuwM6\getRoadizCore_Solr_ClientService::ContainerZnsuwM6\{closure}
#18 /var/cache/prod/ContainerZnsuwM6/App_KernelProdContainer.php(447): ContainerZnsuwM6\App_KernelProdContainer::createProxy
#17 /var/cache/prod/ContainerZnsuwM6/getRoadizCore_Solr_ClientService.php(29): ContainerZnsuwM6\getRoadizCore_Solr_ClientService::do
#16 /var/cache/prod/ContainerZnsuwM6/App_KernelProdContainer.php(429): ContainerZnsuwM6\App_KernelProdContainer::load
#15 /vendor/symfony/dependency-injection/Container.php(237): Symfony\Component\DependencyInjection\Container::make
#14 /vendor/symfony/dependency-injection/Container.php(219): Symfony\Component\DependencyInjection\Container::get
#13 /vendor/roadiz/core-bundle/src/SearchEngine/ClientRegistry.php(26): RZ\Roadiz\CoreBundle\SearchEngine\ClientRegistry::getClient
#12 /vendor/roadiz/core-bundle/src/SearchEngine/AbstractSearchHandler.php(39): RZ\Roadiz\CoreBundle\SearchEngine\AbstractSearchHandler::getSolr
#11 /vendor/roadiz/core-bundle/src/SearchEngine/AbstractSearchHandler.php(360): RZ\Roadiz\CoreBundle\SearchEngine\AbstractSearchHandler::createSolrQuery
#10 /vendor/rezozero/events-api-models-bundle/src/SearchEngine/ApiSearchHandler.php(118): RZ\EventsApiModelsBundle\SearchEngine\ApiSearchHandler::nativeSearch
#9 /vendor/rezozero/events-api-models-bundle/src/SearchEngine/ApiSearchHandler.php(34): RZ\EventsApiModelsBundle\SearchEngine\ApiSearchHandler::search
#8 /vendor/roadiz/core-bundle/src/Repository/NodesSourcesRepository.php(457): RZ\Roadiz\CoreBundle\Repository\NodesSourcesRepository::findBySearchQuery
#7 /vendor/roadiz/core-bundle/src/SearchEngine/GlobalNodeSourceSearchHandler.php(63): RZ\Roadiz\CoreBundle\SearchEngine\GlobalNodeSourceSearchHandler::getNodeSourcesBySearchTerm
#6 /vendor/roadiz/rozier/src/AjaxControllers/AjaxSearchNodesSourcesController.php(52): Themes\Rozier\AjaxControllers\AjaxSearchNodesSourcesController::searchAction
#5 /vendor/symfony/http-kernel/HttpKernel.php(152): Symfony\Component\HttpKernel\HttpKernel::handleRaw
#4 /vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel::handle
#3 /vendor/symfony/http-kernel/Kernel.php(202): Symfony\Component\HttpKernel\Kernel::handle
#2 /vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php(35): Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner::run
#1 /vendor/autoload_runtime.php(35): require_once
#0 /public/index.php(5): null

How to reproduce

; http://symfony.com/doc/current/performance.html
; Configure OPcache for Maximum Performance
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files = 20000
opcache.interned_strings_buffer = 16
opcache.enable_file_override = 1
opcache.revalidate_freq=0
opcache.validate_timestamps=0
zend.detect_unicode = 0
opcache.preload_user=www-data
opcache.preload=/var/www/html/config/preload.php

Possible workaround

Maybe related to https://bugs.php.net/bug.php?id=77644

So disabling preloading on src/Client.php should allow PHP to execute define() call at runtime.

ambroisemaupate commented 2 years ago

Another workaround

Do not use Solarium\Client but Solarium\Core\Client\Client which does not include side-effects (runtime calls)

thomascorthals commented 2 years ago

Solarium 6.3.0 will remove this constant.

If we want a stable 6.2 release "for the archives", we could release 6.2.7 with a hardcoded constant and 6.3.0 with the constant removed for ongoing development.

@mkalkbrenner What do you think?

mkalkbrenner commented 2 years ago

I agree that we should go back for a hardcoded version number for some time. But I wonder if we could add a test that reproduces the issue to avoid such an error in the future

thomascorthals commented 2 years ago

I tried a simple test, but there's two problems with it.

  1. It doesn't fail, so it's not reproducing the issue.
  2. It runs into PHP bug #80608.

You can see the run in my fork. The PHP bug is unrelated to the behaviour we're seeing. I don't encounter it locally on PHP 8.1.