How to Play Alarm WAV File From PHP Script

Written by steve mcdonnell Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Play Alarm WAV File From PHP Script
Write a PHP program to function as an alarm clock. (George Doyle/Stockbyte/Getty Images)

PHP is a server-side scripting language. This means that PHP programs run on a Web server, not on a client's PC. An alarm wave file has to be played on a client's PC for the user to hear it. However, you can use a combination of PHP and JavaScript to accomplish this by creating the alarm functionality with PHP and using PHP to call a JavaScript function to play the WAV file at the appropriate time.

Skill level:

Other People Are Reading


  1. 1

    Create a new PHP program file with an editor. For example, type:

    nano alarm.php

  2. 2

    Store the name of the WAV file in a variable. For example, type:

    <?php $audio = "alarm.wav";

  3. 3

    Store the ending time for the alarm in a variable using the strtotime function. For example, type:

    $ending_time = strtotime("+ 10 minutes");

  4. 4

    Create a loop in PHP that simply waits until the current time exceeds the ending time. For example, type:

    while (strtotime("now") < $ending_time);

  5. 5

    Output a JavaScript script that plays the audio file. For example, type:

    echo '<script language="JavaScript">self.location = "' . $audio . '";</script>'; ?>

  6. 6

    Exit the editor and save the file. Browse to the alarm.PHP program and test the functionality.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.