Ok ill give you a quick idea of what i am trying to accomplish. I have a script that sends a command to the server (linux) to play a playlist of audio files, the playlist is just an array with the song names in it. When i play a song i need to record the PID # of the operation so if i have to kill it i can. And it also has to record how long the song was playing for.
The Problem is that when i run the script it plays the way i want to to but it does not update my db with the songs PID until after it is done.
Heres my code so far:
The Problem is that when i run the script it plays the way i want to to but it does not update my db with the songs PID until after it is done.
Heres my code so far:
Code:
function set_var($name, $val) {
$dbhandle = new PDO('sqlite:../../data/intel.db');
$dbhandle->exec("UPDATE vars SET value = '$val' WHERE name = '$name'");
return get_vars($dbhandle);
}
set_var('php_pid' , $php_pid );
$php_pid = getmypid(); // Gets the php script pid I also need that.
set_var('php_pid' , $php_pid );
print "Php Script is running with PID - $php_pid<br>";
$songs = array ('PhilCollins.mp3');
function madplayer ( $songs )
{
foreach ($songs as $song)
{
$song_time = 0;
$start_time = get_computer_time();
set_var ('last_played' , $song );
set_var( 'mp_pid' , system ("madplay -m /mnt/cf/music/$song & echo \$!" ));
print $pid;
#set_var ('mp_pid' , $pid );
print "<hr>";
print "Pid -- $pid";
print "<hr>";
$song_time = calc_timeString ( get_computer_time() - $start_time );
set_var( 'song_time' , $song_time );
set_log( " song_time -- $song_time " );
}
}
Comment