image-optimize-command: PHP Fatal error: Uncaught Error: Call to undefined method Symfony\Component\Process

First of all, thank you for this great WP CLI script. Really hope to get it running on our system. Running the following command:

wp image-optimize attachment 12660 --allow-root

On this machine:

Ubuntu 18.04.1 LTS
PHP 7.2.15-0

Which results in this error:

PHP Fatal error:  Uncaught Error: Call to undefined method Symfony\Component\Process\Process::fromShellCommandline() in /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php:97
Stack trace:
#0 /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php(77): Spatie\ImageOptimizer\OptimizerChain->applyOptimizer(Object(Spatie\ImageOptimizer\Optimizers\Jpegoptim), Object(Spatie\ImageOptimizer\Image))
#1 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(73): Spatie\ImageOptimizer\OptimizerChain->optimize('/var/www/html/w...')
#2 [internal function]: TypistTech\ImageOptimizeCommand\Operations\Optimize->TypistTech\ImageOptimizeCommand\Operations\{closure}('/var/www/html/w...')
#3 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(74): array_map(Object(Closure), Array)
#4 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/AttachmentImages/Optimize.php(104): TypistTech\ImageOptimizeCommand in /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php on line 97

The install went as following:

wp package install typisttech/image-optimize-command:@stable --allow-root
Installing package typisttech/image-optimize-command (@stable)
Updating /root/.wp-cli/packages/composer.json to require the package...
Using Composer to install the package...
---
Loading composer repositories with package information
Updating dependencies
Resolving dependencies through SAT
Looking at all rules.
Something's changed, looking at all rules again (pass #1)

Dependency resolution completed in 5.266 seconds
Analyzed 6338 packages to resolve dependencies
Analyzed 542383 rules to resolve dependencies
Package operations: 7 installs, 0 updates, 0 removals
Installs: symfony/finder:v4.2.3, symfony/polyfill-ctype:v1.10.0, symfony/filesystem:v4.2.3, symfony/process:v4.2.3, psr/log:1.1.0, spatie/image-optimizer:1.1.5, typisttech/image-optimize-command:0.3.1
 - Installing symfony/finder (v4.2.3)
 - Warning: typisttech/image-optimize-command 0.3.1 requires symfony/finder ^4.1 -> satisfiable by symfony/finder[4.1.x-dev, 4.2.x-dev, 4.3.x-dev, v4.1.0, v4.1.0-BETA1, v4.1.0-BETA2, v4.1.0-BETA3, v4.1.1, v4.1.10, v4.1.11, v4.1.2, v4.1.3, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0, v4.2.0-BETA1, v4.2.0-BETA2, v4.2.0-RC1, v4.2.1, v4.2.2, v4.2.3].
 - Installing symfony/polyfill-ctype (v1.10.0)
 - Warning: symfony/filesystem v4.2.3 requires symfony/polyfill-ctype ~1.8 -> satisfiable by symfony/polyfill-ctype[1.11.x-dev, v1.10.0, v1.8.0, v1.9.0].
 - Installing symfony/filesystem (v4.2.3)
 - Warning: typisttech/image-optimize-command 0.3.1 requires symfony/filesystem ^4.1 -> satisfiable by symfony/filesystem[4.1.x-dev, 4.2.x-dev, 4.3.x-dev, v4.1.0, v4.1.0-BETA1, v4.1.0-BETA2, v4.1.0-BETA3, v4.1.1, v4.1.10, v4.1.11, v4.1.2, v4.1.3, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0, v4.2.0-BETA1, v4.2.0-BETA2, v4.2.0-RC1, v4.2.1, v4.2.2, v4.2.3].
 - Installing symfony/process (v4.2.3)
 - Warning: spatie/image-optimizer 1.1.5 requires symfony/process ^4.2 -> satisfiable by symfony/process[4.2.x-dev, 4.3.x-dev, v4.2.0, v4.2.0-BETA1, v4.2.0-BETA2, v4.2.0-RC1, v4.2.1, v4.2.2, v4.2.3].
 - Installing psr/log (1.1.0)
 - Warning: typisttech/image-optimize-command 0.3.1 requires psr/log ^1.0 -> satisfiable by psr/log[1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.x-dev].
 - Installing spatie/image-optimizer (1.1.5)
 - Warning: typisttech/image-optimize-command 0.3.1 requires spatie/image-optimizer ^1.1.3 -> satisfiable by spatie/image-optimizer[1.1.3, 1.1.4, 1.1.5].
 - Installing typisttech/image-optimize-command (0.3.1)
Writing lock file
Generating autoload files
---
Success: Package installed.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

When I undo the last patch and replace:

$process = Process::fromShellCommandline($command);

With:

$process = new Process($command);

The script works again…

Solution found: Install wp cli via composer instead of phar.

This is because phar bundles with symfony/process v2 and v2 is always loaded (even though a newer version of it is installed).

Using composer resolve the issue.

For those using Trellis, check out https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer

Re-open this issue if you have a better solution.

thank you opicron! $process = new Process($command);