Skip to content

support dropping more extensions while restart #174

Closed

Description

@staabm

phpstan is happily using xdebug-handler to restart when xdebug is loaded, mainly for performance reasons.

we got some new reports from users that other extensions cause similar problems for phpstan, namely pcov and tideways.

our idea is to restart the phpstan process in a similar way xdebug-handler is restarting it already when pcov or tideways is loaded. at best this could happen in one turn, so we don't need multiple restarts when multiple of those extensions are loaded.

what do you think about extending xdebug-handler to allow restart on other extensions?
I think we would only need some kind of "blacklist" so the xdebug handler can drop extension XYZ when loaded and do a restart.

Activity

  1. johnstevenson commented on Oct 16, 2026

    @johnstevenson
    Member

    It is pretty straightforward to extend it yourself. Something like:

    class Restarter extends XdebugHandler
    {
        private $extensions = [];
    
        protected function requiresRestart(bool $default): bool
        {
            if (extension_loaded('pcov')) {
                $this->extensions[] = 'pcov';
            }
            
            return $default || count($this->extensions) > 0;
    
        }
    
        protected function restart(array $command): void
        {
            if (count($this->extensions) > 0) {
                $content = file_get_contents((string) $this->tmpIni);
                
                foreach ($this->extensions as $extension) {
                    $regex = '/^\s*(zend_extension\s*=.*'.$extension.'.*)$/mi';
                    $content = preg_replace($regex, ';$1', $content).PHP_EOL;
                }            
                file_put_contents((string) $this->tmpIni, $content);
            }
    
            parent::restart($command);
        }
    }
  2. staabm commented on Oct 16, 2026

    @staabm
    Author

    works perfect, thank you so much

  3. staabm commented on Oct 16, 2026

    @staabm
    Author

    after more testing, I realized the regex needs to support both extension variants:

    $regex = '/^\s*((?:zend_)?extension\s*=.*' . $extension . '.*)$/mi';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions