3

我有一个 Red5 应用程序,它定义了一些公共 Java 方法。当我启动服务器时,应用程序类的一个对象被创建。我正在尝试使用 Java 应用程序类的现有实例从 PHP 调用应用程序类的公共方法。

所以这是我的 Java 应用程序:

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()
    {
    }
}

从 PHP 中,我想访问创建的 App 对象并调用f()它的方法。

我试过玩这个叫做“上下文”的东西。所以在 Java 方法App.appStart()中,我这样做了:

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

在 PHP 中,我尝试像这样访问保存的对象:

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

不幸的是,java_is_null()PHP 中的函数返回true.

我还尝试将 App 对象保存在 App 类的静态变量中,但是当我在 PHP 中访问该变量时,它的值为null.

4

4 回答 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

于 2012-10-08T14:21:00.680 回答
1

我遇到了一个库,可以让您从 PHP 客户端连接到 Red5 应用程序。我现在使用它而不是 PHP/Java Bridge。你可以在这里找到它:code.google.com/p/php-rtmp-client

于 2012-10-08T15:09:05.950 回答
0

很少有技术可以帮助您实现 php/Java 桥接、SOAP、Zend 的供应商特定框架或 Caucho 的 J2EE 应用服务器、IBM 的 Eclipse 零框架

我推荐 php/java 桥接器。

于 2013-07-03T11:54:11.427 回答
0

我认为您的 PHP Web 服务器无法加载 Java.inc。

请按照这些步骤检查,它对我有用

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

于 2012-10-08T14:26:07.973 回答