gpt4 book ai didi

php - 如何使用 PHP 运行 Linux 后台进程?尝试使用系统 ("sudo -u me mplayer/tmp/audio.wav") 但不工作

转载 作者:IT王子 更新时间:2023-10-29 00:32:12 26 4
gpt4 key购买 nike

当我执行以下操作时,没有任何效果(使用 ps aux | grep mplayer 检查,其中 1.wav 是一个 10 分钟的音频文件):

system("mplayer /tmp/1.wav"); // failed
system("sudo -u myusername mplayer /tmp/1.wav"); // failed
system("mplayer /tmp/1.wav &"); // failed
system("(mplayer /tmp/demo.wav) >/dev/null &"); //failed according to: http://www.php.net/manual/fr/function.system.php#88543
system("sudo -u myusername -i mplayer /tmp/demo.wav");

如何使用 PHP 运行后台进程?只有这个有效,但它就像批处理文件,我在同一个系统中。 $ php -r "system('mplayer/tmp/demo.wav');";

谢谢

注意:1)错误:

Cannot find HOME directory.
Home directory /var/www not ours.
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
Home directory /var/www not ours.
waitpid(): No child processes
[AO_ALSA] alsa-lib: pulse.c:229:(pulse_connect) PulseAudio: Unable to connect: Internal error

[AO_ALSA] Playback open error: Connection refused
Failed to initialize audio driver 'alsa'
[AO OSS] audio_setup: Can't open audio device /dev/dsp: No such file or directory
Home directory /var/www not ours.
waitpid(): No child processes
[AO_ALSA] alsa-lib: pulse.c:229:(pulse_connect) PulseAudio: Unable to connect: Internal error

[AO_ALSA] Playback open error: Connection refused
Home directory /var/www not ours.
AO: [pulse] Init failed: Connection refused
Home directory /var/www not ours.
waitpid(): No child processes
Home directory /var/www not ours.
[AO_ALSA] alsa-lib: pulse.c:229:(pulse_connect) PulseAudio: Unable to connect: Connection refused

Aborting. $HOME not set!

2) & 5) 错误:

sudo: sorry, you must have a tty to run sudo

3)错误:

Cannot find HOME directory.
File not found: '/tmp/1.wav'
Failed to open /tmp/1.wav.

4)错误:

Cannot find HOME directory.
Home directory /var/www not ours.
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
Home directory /var/www not ours.
waitpid(): No child processes
[AO_ALSA] alsa-lib: pulse.c:229:(pulse_connect) PulseAudio: Unable to connect: Internal error

[AO_ALSA] Playback open error: Connection refused
Failed to initialize audio driver 'alsa'
[AO OSS] audio_setup: Can't open audio device /dev/dsp: No such file or directory
Home directory /var/www not ours.
waitpid(): No child processes
[AO_ALSA] alsa-lib: pulse.c:229:(pulse_connect) PulseAudio: Unable to connect: Internal error

[AO_ALSA] Playback open error: Connection refused
Home directory /var/www not ours.
waitpid(): No child processes
AO: [pulse] Init failed: Internal error
Home directory /var/www not ours.
waitpid(): No child processes
Home directory /var/www not ours.
waitpid(): No child processes
[AO_ALSA] alsa-lib: pulse.c:229:(pulse_connect) PulseAudio: Unable to connect: Internal error

Aborting. $HOME not set!

最佳答案

显然,没有简单的方法可以做到这一点:system() 函数或反引号符号都不允许您运行后台任务……有人发布了一个(相当麻烦的)解决方案PHP doc website .

关于php - 如何使用 PHP 运行 Linux 后台进程?尝试使用系统 ("sudo -u me mplayer/tmp/audio.wav") 但不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6246383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com