I am logged in to linux feora 15 distro with username: stackoverflow.
My browser execute in the local system a PHP script to play a music using PHP system(“mplayer /tmp/stackoverflow.wav”), passthru(“mplayer /tmp/stackoverflow.wav”) command. Such as linux command.
As a user stackoverflow i dont hear any audio. But i can see that mplayer /tmp/stackoverflow.wav is running which has duration of 8minutes audio.
My question is: how can i use PHP system(“mplayer /tmp/stackoverflow.wav”); to switch user and run the same command, so that i can hear my music with my PHP?
<?php
// for example
switchuser("su stackoverflow password");
system("mplayer /tmp/itworks.wav");
?>
The direct answer to your question would be to use
sudo, as inBut, I’m not sure this will solve your problem. Firstly, where do you want the sound outputted? The server or the client/browser? The above technique will work on the server. For the browser, you’d need to get the client to load the .wav file as an object or some such and deal with it, presumably via a plugin.
You mention that you can see a running mplayer process though? If you are at the server (or the server and client are on the same physical machine) and you can’t hear any output, then there’s something else going on. It’s possible that the web server process user doesn’t have permission to use the audio card, but then I doubt the mplayer process would continue for so long without terminating with “permission denied” error. To figure this out, we’d need more info I guess