Page 1 of 1

[SOLVED] Executing a file for a timer?

Posted: Wed May 25, 2005 1:38 pm
by Sphen001
Hi,

I've got a question for you.

I am wondering what is the best way to execute a audio file is. I'm building a timer script that plays a audio file when the time is up. Right now, I can only think of using HTML to embed an audio file if certain conditions are met, but if there's a better way, I would like to try it.

Come to think of it, maybe you could check my theory, and see if it's ok.

Basically, the user selects an amount of time to count (ie. 30 mins). Script gets current time and current time + amount of time selected above. Page refreshes every minute (done by a HTML redirect...if you can think of a better way, I would love to hear it), and if current time is equal or greater to end time, play the file.

Please give me your comments, suggestions, etc.

Thanks,

Sphen001

Posted: Wed May 25, 2005 3:30 pm
by thomas777neo
Suggestion:

Create a text file with php or a session, with the time now + added time.

I your code do something like this:

Code: Select all

while (true)
{
    if ($_SESSION['time'] <= the time now) // check if expired
    {
        // play audio file
    }
        else
        {
            sleep(60); // if not sleep for 1 minute
        }
}

Posted: Wed May 25, 2005 7:40 pm
by Sphen001
Hi,

Thanks for the code. It's a much better way of doing it. I still have one question though. Do you know of any way to get a file to execute upon certain conditions?

Thanks for any help

Sphen001

Posted: Wed May 25, 2005 8:46 pm
by John Cartwright
What conditions?

Code: Select all

if ($variable == 'somevar')
{
     //send header
     header();
}
else
{
     //deny
}


I wouldn't recommend using sleep that way.
Some malicious user could do some damage with it setup like that.

Posted: Thu May 26, 2005 6:56 am
by Sphen001
Hi,

Basically, if the current time == the end time, play an audio file, if not, wait another minute, then check again.

Sphen001