I’ve updated my “parameterdemo” to include a couple PHP pages. The latest trunk (0.8.1-dev) now supports PHP through the use of Quercus. To enable it simply set a context parameter in your web.xml and include the quercus and resin-utils jars in your WEB-INF/lib. See the zip file for a complete example (eclipse + ant).
Once you deploy the war, go to these urls to test (update your port to match your servers setting):
PHP example getting value from Red5 application:Â
<a href="http://localhost/parameterdemo/getparam.php">http://localhost/parameterdemo/getparam.php</a>
Same example with debug output:Â
<a href="http://localhost/parameterdemo/getparam.php?debug=true">http://localhost/parameterdemo/getparam.php?debug=true</a>
Java servlet example:Â
<a href="http://localhost/parameterdemo/myservlet">http://localhost/parameterdemo/myservlet</a>
The web.xml entry must look like so:
<context-param> <param-name>enable-php</param-name> <param-value>true</param-value> </context-param>
Note: You dont have to install Resin to use Quercus, simply download one of the wars on this page: http://quercus.caucho.com/ and grab the libraries from WEB-INF/lib
Tags: bean, Java, parameter, PHP, Red5, servlet
I recall seeing a question from a user about accessing servlet parameters from their Red5 application, so I have created a small demo which shows how to not only access sevlet parameters from Red5 apps but the other way around as well.
Retrieve a servlet context parameter from inside a Red5 application (AppContext -> Servlet)
1. Grab a reference to the application context
ApplicationContext appCtx = getContext().getApplicationContext();
2. Get the servlet context
ServletContext ctx = ((XmlWebApplicationContext) appCtx).getServletContext();
3. Get the context parameter
String param = ctx.getInitParameter("myparam");
Retrieve an application context parameter from a inside a servlet (Servlet -> AppContext)
1. Get the servlet context
ServletContext ctx = getServletContext();
2. Grab a reference to the application context
ApplicationContext appCtx = ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
3. Get the bean holding the parameter
MyBean bean = appCtx.getBean("mybean");
String param = bean.getParameter("myparam");
Sample project files: parameterdemo.zip
Instructions:
Unzip the demo and create a new directory named parameterdemo in your red5/webapps directory, then restart your server.
Open your browser and go here:Â http://localhost/parameterdemo/myservlet?paramName=myparam
You should see “Hello World”
To test the Red5 application you will need to create a Flex or Flash application that connects to: rtmp://localhost/parameterdemo
Then simply call “getParameter” passing a parameter name you want the value of. The name must match a context param in the web.xml file.