I uploaded new version of extension on Magento Marketplace. And I've got Code Sniffer error during technical testing:

The use of function exec() is forbidden
severity : 10
Line : 441
Column : 17
Source : Magento2.Security.InsecureFunction.Found

How should I replace exec() ?

I use server command and cannot just delete exec().

  • can you provide info what you are trying to exec? executing commands will always be unsafe. you should try to implement what the stuff in exec does in PHP Oct 23, 2019 at 9:25
  • This is command for exec: identify -ping "/path/to/image/file/phpCB6C.tmp"
    – PHPer
    Oct 23, 2019 at 9:43
  • 1
    you can definitly do the same in PHP. however "-ping" seems to not to be a valid option. imagemagick.org/script/identify.php Oct 23, 2019 at 10:46

1 Answer 1


use Magento\Framework\ShellInterface

example in Magento\Cron\Observer\ProcessCronQueueObserver (execute method)

  • Thank you. It will be useful to know. In my case, I solved the problem by deleting exec() and use getimagesize() instead.
    – PHPer
    Oct 23, 2019 at 13:20
  • hi @vitalli, can you update me code to run upgrade command using shellinterface
    – Manjunath
    Jan 20, 2021 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.