3

I have a Red5 application which defines some public Java methods. When I start the server, an object of the application class gets created. I am trying to call the public methods of the application class from PHP using the existing instance of the Java application class.

So here's my Java application:

public class App extends org.red5.server.adapter.ApplicationAdapter
{
    public boolean appStart(IScope app)
    {
        // This method gets called when the application starts
        // and an object of this App class is created.
        return true;
    }

    // This is the method I would like to call from PHP.
    public void f()
    {
    }
}

From PHP, I would like to get access to the App object that is created and call the method f() on it.

I have tried playing around with this thing called "context". So in the Java method App.appStart(), I did this:

// Save a reference to this App object to be retrieved later in PHP.
new PhpScriptContextFactory().getContext().put("x", this);

And in PHP, I tried to access the saved object like this:

require_once("http://localhost:5080/JavaBridge/java/Java.inc");
var_dump(java_is_null(java_context()->get("x")));

Unfortunately, the java_is_null() function in PHP returns true.

I also tried saving the App object in a static variable of App class but when I access that variable in PHP, its value is null.

0

4 Answers 4

1

I think your post is rather incomplete as we can't see what JavaBridege/java/Java.inc does look like.

The second doubt is about what you try to do here. You want to call a Java function from PHP? Why don't you create a simple Servlet that triggers your call to the Application. You can then access the Servlet's URL and perform a call via cURL for example.

Calling a Java function "raw" is not recommended at all, I mean this function is loaded into the JVM and you should provide an API in your Java program to access this code or method. Remember that this Java code isloaded into Apache Tomcat and loaded via Spring as part of the Red5 framework. So it is much more then a simple Java Class. I doubt that triggering a method into the ApplicationAdapter the way you propose here is possible at all.

Sebastian

Sign up to request clarification or add additional context in comments.

Comments

1

I came across a library that lets you connect to the Red5 app from a PHP client. I am using it now instead of PHP/Java Bridge. You can find it here: code.google.com/p/php-rtmp-client.

1 Comment

Yes that sound more good then your previous approach. Either you connect via RTMP or HTTP. But doing "raw" Java JVM digging for Java Instances is not the way to do it.
0

I think your PHP web server is not able to load Java.inc.

Please follow these steps and check, it has worked for me

http://php-java-bridge.sourceforge.net/pjb/desktop-apps.php

1 Comment

Java.inc is loaded and I am able to create objects of Java classes in PHP. What I am trying to do is access the already created Java object of class App.
0

there are few technology which will help you php/Java bridge, SOAP, a vendor-specific framework from Zend or a J2EE application server from Caucho, IBM's Zero framework for Eclipse

I recommend php/java bridge.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.