What if you could run PHP code directly inside ColdFusion?
Posted by James Harvey
at 8:42 AM on Nov 12, 2008
0 comments - Posted In:
Cold Fusion | PHP
I found this blog post back in early 2008 that states you can run PHP (and Ruby) on Coldfusion 8. I thought this was pretty damed cool, especially considering I develop with both. So here's the Blog entry:
What if you could run PHP code directly inside ColdFusion?
<cf_php>
<?php
echo "Hello ".$_COLDFUSION["who"]."<br />";
$_COLDFUSION["greeting"] = "wibble";
?>
</cf_php>
<cfoutput>greeting = #greeting#</cfoutput>
This outputs Hello Sean and greeting = wibble. Yes, you can pass ColdFusion variables into PHP and set variables in PHP that you can access back in ColdFusion land. [Note: Unlike the first version I posted, the new version takes no attributes but instead makes available the entire variables scope from the calling page - and now uses $_COLDFUSION which is more in keeping with PHP.]
How is this possible? Well, ColdFusion 8 uses Java 6 which provides access to the javax.script package and all the J-language implementations available. Quercus is a Java implementation of PHP and it is implemented as a script engine.
Sun has provided a number of JSR-223 ScriptEngine and ScriptEngineFactory implementations and there are Java implementations of a number of languages.
Combine that with a simple custom tag and the code you see above becomes a trivial extension for ColdFusion 8!
Installation instructions are given inside each script directory's example.cfm page. The project now has Ruby support.
The source code is available on Google Code - along with my other Open Source projects and I'm setting up a central location on RIAForge as well (as soon as Ray approves my project request).
You can also download the code here, as well as in my Downloads Section.

0 responses to “What if you could run PHP code directly inside ColdFusion? ”