Example #1
0
File: mwget.php Project: n2i/xvnkb
#-------------------------------------------------------------------------
define('MW_STORAGE_ROOT', str_replace('\\', '/', dirname(__FILE__)) . '/');
define('MW_STORAGE_WAVE', MW_STORAGE_ROOT . 'wave/');
define('MW_LOOKUP_URL', 'http://www.m-w.com/dictionary/');
define('MW_SOUNDS_URL', 'http://www.m-w.com/cgi-bin/audio.pl?');
#-------------------------------------------------------------------------
# Init the interprocess communication queue
#-------------------------------------------------------------------------
$working = true;
$queue = shm_create();
shm_put($queue, array());
#-------------------------------------------------------------------------
# Starting
#-------------------------------------------------------------------------
while ($working) {
    $cmd = shm_get($queue);
    shm_put($queue, array());
    foreach ($cmd as $data => $id) {
        switch ($id) {
            case 'exit':
                $working = false;
                break;
            case 'get':
                # By pass if the file already exists
                if (file_exists(MW_STORAGE_WAVE . $data . '.wav')) {
                    break;
                }
                # Get the word meaning from Mirriam-Webster
                $contents = file_get_contents(MW_LOOKUP_URL . rawurlencode($data));
                # Detect audio URL in the contents
                if (preg_match_all("|javascript:popWin\\('/cgi-bin/audio.pl\\?([^)]+)'\\)|is", $contents, $m)) {
Example #2
0
File: sfc.php Project: n2i/xvnkb
 function getWaveFile()
 {
     global $queue;
     if (!file_exists(SFC_WAVE_PATH . $this->question . '.wav')) {
         $cmd = shm_get($queue);
         $cmd[$this->question] = 'get';
         shm_put($queue, $cmd);
     }
 }