I am in process creating resource/api in Mulesoft and this need to run some PHP script. If I use engine as “php” am getting below error –
“Scripting engine ‘php’ not found. Available engines are: Oracle Nashorn”
So, how to enable php engine?
Advertisement
Answer
PHP is not a valid scripting language for the Java scripting engine, also known as JSR233 because of the Java specification upon which it was implemented. Mule uses JSR233 as the implementation of the Scripting Module, so it can’t even find PHP as a valid language.
Note that Mule runtime is not a web server or a web container, and much less a PHP server. My primary recommendation is to reimplement that page, or to deploy it to an actual PHP server, and do an HTTP request from your Mule application.
If you for some reason can not do it, as you can see in @Martin Zeitler’s answer something like that was already done almost 10 years ago, creating a JSR233 wrapper to use the Quercus library to implement PHP 5 as a scripting language for Java.
That article is from 2012 and for Mule 3.3. The mule-module-php.jar was probably created for that post and is no longer available. Even if you find it, there is a chance that it will not be compatible with current Mule releases (ie 3.9.5), and it is certainly compatible with Mule 4.3. It was based on the Quercus library that seems abandoned in the last 6 years.
Having said that, if you are willing to depend on outdated technologies, you can try to re-implement the same functionality yourself by creating a Java library that encapsulates Quarcus and add it to your Mule 4 project as a dependency.