test_wpipe.php 1.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#!/usr/bin/php
<?php
    define('PIPE_CMD',           '/tmp/pipe_cmd');
    define('PIPE_RESPONSE',      '/tmp/pipe_response');
    define('PIPE_MODE',          0600);

    set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
    include 'show_source_include.php';
    include "elphel_functions_include.php"; // includes curl functions
    $cmd = 'STATUS';
    $kw = 'CMD';
    if (count($argv) > 2){
        $kw = $argv[1];
        $cmd = $argv[2];
    } else if (count($argv) > 1){
        $cmd = $argv[1];
    }
    
    $mode=0600;
    if(!file_exists(PIPE_CMD)) {
      // create the pipe
        umask(0);
        posix_mkfifo(PIPE_CMD,$mode);
    }
    if (file_exists(PIPE_RESPONSE)){
        unlink(PIPE_RESPONSE); //delete old pipe
    }
    $f = fopen(PIPE_CMD,"w");
//    sleep(1);
    $cmds = $kw.' = '.$cmd."\n";
    
    fwrite($f,$cmds);
//    sleep (1);
    echo "(w) sent commands:\n".$cmds."\n";
    fclose ($f);
//    sleep(1);
    echo "(w) closed\n";
    if ($cmd == 'STATUS') {
        while (!file_exists(PIPE_RESPONSE)); // just wait
        echo "(w) got PIPE_RESPONSE\n";
        $fl = file(PIPE_RESPONSE);
        var_dump($fl);
        unlink(PIPE_RESPONSE); //delete pipe
    }
?>