从PHP脚本执行程序


Executing a program from PHP script

我正在尝试执行命令exec('vlc');从PHP脚本(在linux中),但是,页面(php)还没有加载。即使使用pcntl_fork(对于exec命令),这也不起作用。

但是如果我试图从命令行php -S localhost:8000 -t path/to/src运行,在浏览器中输入localhost:8000/page.php,页面加载完成,vlc打开。

有什么问题?

注意:如果我试图从命令行php -r "exec('vlc');"运行,vlc打开。

另外,我检查了一下,php不能在安全模式下工作。

Update1:

<?php
echo shell_exec('vlc');
?>

**** 不工作 ****

<?php
echo shell_exec('vlc 2>&1');
?>
输出:

主目录不可访问:Permission denied [08ea1490] pulse audio output error: PulseAudio server connection failure: connection refused [08e9e448] core libvlc error: interface "globalhotkeys,none" initialization failed [08e9e448] dbus interface error:连接D-Bus session daemon失败:无法自动启动dbus daemon,如果没有$DISPLAY for X11 [08e9e448] core interface error:no suitable interface module [08ded0d0] core libvlc error: interface "dbus,none" initialization failed [08ded0d0] core libvlc:使用默认接口运行vlc。使用'cvlc'来使用没有接口的vlc。[08e9e448] qt4接口错误:Could not connect to X server [08e9e448] skins2接口错误:cannot initialize OSFactory [08e9e448] [cli] lua接口:Listening on host "*console"VLC媒体播放器2.2.0 Weatherwax

<?php
echo shell_exec('whoami');
?>

输出:www-data

/var/log/httpd  

不存在

but /var/log/apache2/error.log exists and

Home directory not accessible: Permission denied
[0980c490] pulse audio output error: PulseAudio server connection failure: Connection refused
[09809448] core interface error: no suitable interface module
[097580d0] core libvlc error: interface "globalhotkeys,none" initialization failed
[09809448] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[09809448] core interface error: no suitable interface module
[097580d0] core libvlc error: interface "dbus,none" initialization failed
[097580d0] core libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
[09809448] qt4 interface error: Could not connect to X server
[09809448] skins2 interface error: cannot initialize OSFactory
[09809448] [cli] lua interface: Listening on host "*console".
[09809448] [cli] lua interface: Requested shutdown.

更新2:

shell_exec("DISPLAY=:0  vlc");

工作,但非常慢(与php -S ...,是更快)。

I trying

 shell_exec("DISPLAY=:0  vlc v4l2:///dev/video0 --sout '.settings.'");

(与一些设置),但我收到一个错误

[b4602c50] mux_ogg mux: Open
[b4604a30] v4l2 demux error: cannot open device '/dev/video0': Permission denied
[b4604a30] v4l2 demux error: cannot open device '/dev/video0': Permission denied
[b4604a30] v4l2 access error: cannot open device '/dev/video0': Permission denied
[b4b04ea0] core input error: open of `v4l2:///dev/video0' failed
[b4b04ea0] core input error: Your input can't be opened
[b4b04ea0] core input error: VLC is unable to open the MRL 'v4l2:///dev/video0'. Check the log for details.
[b4602c50] mux_ogg mux: Close

,但与php -S ...工作

有什么问题?

Thanks in advance

我没有足够的声誉来发表评论,这使得调试有点困难。首先检查/var/log/httpd中的错误日志,看看那里是否有什么明显的东西。如果什么都没有,你能执行这个命令并告诉我们它有什么用吗?

<?php
echo shell_exec('vlc');
?>

如果没有效果

<?php
echo shell_exec('vlc 2>&1');
?>

<?php
echo shell_exec('whoami');
?>