简体   繁体   English

Symfony2流程不会实时提供反馈

[英]Symfony2 Process doest't give feedback in real-time

my idea is to start a minecraft server with the Symfony2 Process Class and want to give feedback to me in real time. 我的想法是使用Symfony2 Process Class启动一个Minecraft服务器,并希望实时向我提供反馈。 So, like described in the Process cookbook part , I try the following code: 因此,如Process cookbook部分所述 ,我尝试以下代码:

$process = new Process('sudo java -jar -Xms512M -Xmx1G ../server/minecraft_server.jar');
    $process->setTimeout(null);
    $process->run(function ($type, $buffer) {
        if ('err' === $type) {
            echo 'ERR > '.$buffer;
        } else {
            echo 'OUT > '.$buffer;
        }
    });

Because of some permission issues with the apache2 user i modified the sudoers file with this: www-data ALL = (myspecialUser) NOPASSWD: /usr/bin/java 由于apache2用户的一些权限问题我用这个修改了sudoers文件: www-data ALL = (myspecialUser) NOPASSWD: /usr/bin/java
so the www-data user can run the java command. 所以www-data用户可以运行java命令。

The server is starting in the background, but my problem is now that I'm not getting any real-time output. 服务器在后台启动,但我现在的问题是我没有得到任何实时输出。 Only if I shutdown (or kill) the minecraft server process I get the output. 只有当我关闭(或杀死)Minecraft服务器进程时,我才得到输出。

Any suggestions how to get a real-time output? 有关如何获得实时输出的任何建议吗?

Instead of calling the run() method, you should try with the start() one: 您应该尝试使用start()方法,而不是调用run()方法:

$process = new Process('sudo java -jar -Xms512M -Xmx1G ../server/minecraft_server.jar');
$process->setTimeout(null);
$process->start(function ($type, $buffer));

echo 'OUT >' . $process->getOutput();

http://api.symfony.com/master/Symfony/Component/Process/Process.html#method_start http://api.symfony.com/master/Symfony/Component/Process/Process.html#method_start

http://api.symfony.com/master/Symfony/Component/Process/Process.html#method_getOutput http://api.symfony.com/master/Symfony/Component/Process/Process.html#method_getOutput

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM