[SOLVED] Executing a file for a timer?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

[SOLVED] Executing a file for a timer?

Post 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
Last edited by Sphen001 on Tue Jul 12, 2005 9:19 pm, edited 1 time in total.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post 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
        }
}
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

Hi,

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

Sphen001
Post Reply