Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal error: Uncaught Error: Call to undefined method Symfony\Component\Process #37

Open
opicron opened this issue Feb 17, 2019 · 10 comments

Comments

@opicron
Copy link

@opicron opicron commented Feb 17, 2019

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.

@TangRufus

This comment has been minimized.

Copy link
Member

@TangRufus TangRufus commented Feb 17, 2019

Although I see Installing symfony/process (v4.2.3), can you confirm symfony/process v4.2.3 is loaded?

Related:

Tips:
WP CLI doesn't provide easy way to check it. My suggestion would be looking into your wp package path. You will find the underlying composer installation there.

@opicron

This comment has been minimized.

Copy link
Author

@opicron opicron commented Feb 18, 2019

I am unsure how to check if the symfony/process is loaded. However checking the /vendor/symfony/process/ path the php scripts are installed.

Running the install command an second time gives no warnings or errors. I assume the correct version is installed.

EDIT: The process component Changlog states 4.2.0.

I manually downloaded symfony/process 4.2.3 and replaced the old version. I uploaded an new image and tried to optimize it but it fails with the same error.

@opicron

This comment has been minimized.

Copy link
Author

@opicron opicron commented Feb 18, 2019

When I undo the last patch and replace:

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

With:

$process = new Process($command);

The script works again..

@eboy79

This comment has been minimized.

Copy link

@eboy79 eboy79 commented Feb 24, 2019

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

@yavane

This comment has been minimized.

Copy link

@yavane yavane commented Apr 13, 2019

This is still a valid error :(

But can be fixed with changes from above.

@Redjam

This comment has been minimized.

Copy link

@Redjam Redjam commented May 23, 2019

Error is still valid. The fix proposed by @opicron works well. Is it possible du push it in the branch for future users?

@jbonlinea

This comment has been minimized.

Copy link

@jbonlinea jbonlinea commented Jul 26, 2019

Hi guys

I bumped into the same error as you

could you please detail what changes have you made ?

When I undo the last patch and replace:

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

With:

$process = new Process($command);

The script works again..

what last patch, and what file have you edited ?

Thank's

EDIT

the file to edit is
/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php:97

It works indeed, but I haven't "downgraded to last patch (which is ?)

@Soullighter

This comment has been minimized.

Copy link

@Soullighter Soullighter commented Oct 2, 2019

I hade same error, after replace with @opicron suggestions everything is working fine
Thank you @jbonlinea for directing us to the file 👍

@TangRufus

This comment has been minimized.

Copy link
Member

@TangRufus TangRufus commented Oct 3, 2019

Which version you installed?
Is it 482d9c9 ?

@Soullighter

This comment has been minimized.

Copy link

@Soullighter Soullighter commented Oct 3, 2019

Which version you installed?
Is it 482d9c9 ?

You mean on composer.json?
How to check version?

bensontrent added a commit to bensontrent/image-optimizer that referenced this issue Oct 12, 2019
Fix for error "undefined method Symfony\Component\Process\Process::fromShellCommandline()"  See TypistTech/image-optimize-command#37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
7 participants
You can’t perform that action at this time.