执行PHP脚本 [英] Execute php script

查看:170
本文介绍了执行PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个PHP应用程序。在脚本中,有一个叫执行的jar文件:

 ?PHP
EXEC(Java的罐子模拟/ simulation.jar');
?>
 

现在的问题是,这个命令行执行的jar文件:

 用户@ Ubuntu的:PHP execSimulation.php
 

但不能从网页呼叫。呼叫是通过AJAX做,我失去了一些东西?

 <! - 脚本来执行模拟 - >
<脚本类型=文/ JavaScript的SRC =的prototype.js>< / SCRIPT>
        <脚本>

            传播sendRequest将(){
                新的Ajax.Request(ejecutarSimulacion.php
                    {
                    方法:'后',
                    postBody:NAME ='+ $ F(名称),
                    的onComplete:showResponse方法
                    });
                }

            功能showResponse方法(REQ){
            警报(req.responseText);
            }
        < / SCRIPT>

<形式ID =测试的onsubmit =返回false;>
                                <输入类型=隐藏值=< PHP的echo $ simulacion;>中NAME =名称ID =名与GT;
                                <输入类型=提交值=< PHP的echo $ NOMBRE;>中的onClick =sendRequest将()>
                            < /形式GT;
 

当我尝试只打印参数我送,例如,警报显示,所以我敢肯定,呼叫到达服务器,但我不知道为什么不执行的jar文件。任何想法,请?

在此先感谢。

修改

错误跟踪:

 没有指定协议
在线程异常主要java.lang.InternalError:无法连接到X11窗口服务器使用':0.0作为显示变量的值。
    在sun.awt.X11GraphicsEnvironment.initDisplay(本机方法)
    在sun.awt.X11GraphicsEnvironment.access $ 200(X11GraphicsEnvironment.java:62)
    在sun.awt.X11GraphicsEnvironment $ 1.运行(X11GraphicsEnvironment.java:178)
    在java.security.AccessController.doPrivileged(本机方法)
    在sun.awt.X11GraphicsEnvironment< clinit>(X11GraphicsEnvironment.java:142)
    在java.lang.Class.forName0(本机方法)
    在java.lang.Class.forName(Class.java:186)
    在java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
    在java.awt.Window.init(Window.java:385)
    在java.awt.Window中的< INIT>(Window.java:438)
    在java.awt.Frame中的< INIT>(Frame.java:419)
    在java.awt.Frame中的< INIT>(Frame.java:384)
    在javax.swing.JFrame中的< INIT>(JFrame.java:174)
    在org.opensourcephysics.tools.TranslatorTool< INIT>(来源不明)
    在org.opensourcephysics.tools.TranslatorTool< clinit>(来源不明)
    在java.lang.Class.forName0(本机方法)
    在java.lang.Class.forName(Class.java:186)
    在org.opensourcephysics.display.OSPRuntime< clinit>(来源不明)
    在org.opensourcephysics.controls.OSPLog.fine(来源不明)
    在org.opensourcephysics.tools.ResourceLoader.addSearchPath(来源不明)
    在_users.tanqueCalentamiento.TanqueCalentamiento< clinit>(TanqueCalentamiento.java:18)
找不到主类:_users.simulation.Simulation。计划将退出。
 

解决方案

看来你的罐子需要X服务器在运行。

  

无法连接到X11窗口服务器使用':0.0,作为显示变量的值

在命令行中运行它,你有X上运行?如果你这样做,这可以解释为什么它的作品在那里,而不是从PHP。

您可以尝试从PHP劫持运行的X会话。

  EXEC('DISPLAY =:​​0 Java的罐子模拟/ simulation.jar');
 

您可能需要先运行 xhost的+本地主机(或 xhost的+ )在命令行中,允许用户PHP运行为连接至X。

I am building a php application. In a script, there is a call to execute a jar file:

?php
exec('java -jar simulations/simulation.jar');
?>

The problem is that this command line executes the jar file:

user@ubuntu: php execSimulation.php

but not the call from the web page. The call is made by AJAX, am I missing something??

<!-- Script to execute the simulation -->
<script type="text/javascript" src="prototype.js"></script>
        <script>

            function sendRequest() {
                new Ajax.Request("ejecutarSimulacion.php", 
                    { 
                    method: 'post', 
                    postBody: 'name='+ $F('name'),
                    onComplete: showResponse 
                    });
                }

            function showResponse(req){
            alert(req.responseText);
            }
        </script>

<form id="test" onsubmit="return false;">
                                <input type="hidden" value="<?php echo $simulacion; ?>" name="name" id="name" >
                                <input type="submit" value="<?php echo $nombre; ?>" onClick="sendRequest()">
                            </form>

When I try to print only the param I send, for instance, the alert shows it, so I am sure that the call is reaching the the server, but I don't know why the jar file is not executed. Any ideas, please?

Thanks in advance.

EDIT

Error trace:

No protocol specified
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:62)
    at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:178)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:142)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
    at java.awt.Window.init(Window.java:385)
    at java.awt.Window.<init>(Window.java:438)
    at java.awt.Frame.<init>(Frame.java:419)
    at java.awt.Frame.<init>(Frame.java:384)
    at javax.swing.JFrame.<init>(JFrame.java:174)
    at org.opensourcephysics.tools.TranslatorTool.<init>(Unknown Source)
    at org.opensourcephysics.tools.TranslatorTool.<clinit>(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at org.opensourcephysics.display.OSPRuntime.<clinit>(Unknown Source)
    at org.opensourcephysics.controls.OSPLog.fine(Unknown Source)
    at org.opensourcephysics.tools.ResourceLoader.addSearchPath(Unknown Source)
    at _users.tanqueCalentamiento.TanqueCalentamiento.<clinit>(TanqueCalentamiento.java:18)
Could not find the main class: _users.simulation.Simulation. Program will exit.

解决方案

It seems your jar requires an X server to be running.

Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.

When you run it from command line, do you have X running? If you do, this would explain why it works there, and not from PHP.

You can try to "hijack" the running X session from PHP.

exec('DISPLAY=:0 java -jar simulations/simulation.jar');

You may have to first run xhost +localhost (or xhost +) from the command line, to allow the user PHP is running as to connect to X.

这篇关于执行PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆