Example #1
0
        break;
    case "test":
        if (!$port) {
            echo "No port specified\n";
            exit(0);
        }
        $n = 30;
        $secs = 60;
        for ($i = 0; $i < $n; $i++) {
            echo CMLLPServer::send($host, $port, "\v" . CMLLPServer::sampleMessage() . "\r");
            usleep($secs * 1000000);
        }
        break;
    case "list":
        if (!in_array($host, array("localhost", "127.0.0.1", "::1"))) {
            outln("Specified host is not local, localhost will be used instead");
        }
        $processes = CMLLPServer::getPsStatus();
        echo "--------------------------------------\n";
        echo "   PID |  PORT | STATUS | PS NAME     \n";
        echo "--------------------------------------\n";
        foreach ($processes as $_pid => $_status) {
            $_ok = isset($_status["ps_name"]) && stripos($_status["ps_name"], "php") !== false;
            $_msg = $_ok ? $msg_ok : $msg_error;
            printf(" %5.d | %5.d | %s | %s \n", $_pid, $_status["port"], $_msg, @$_status["ps_name"]);
        }
        break;
    default:
        echo "Unknown command '{$command}'\n";
        exit(1);
}
Example #2
0
<?php

/**
 * $Id$
 * 
 * @package    Mediboard
 * @subpackage hl7
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html 
 * @version    $Revision$
 */
// CLI or die
PHP_SAPI === "cli" or die;
$root_dir = dirname(__FILE__) . "/../../..";
require "{$root_dir}/modules/hl7/classes/CMLLPServer.class.php";
$tmp_dir = CMLLPServer::getTmpDir();
/**
 * Simple output function
 * 
 * @param string $str The string to output
 * 
 * @return void
 */
function outln($str)
{
    $stdout = fopen("php://stdout", "w");
    fwrite($stdout, $str . PHP_EOL);
}
Example #3
0
            $options[substr($argv[$i], 2)] = $argv[++$i];
            break;
    }
}
// ---- End read arguments
if ($options["cert"] && !is_readable($options["cert"])) {
    outln("SSL certificate not readable: '{$options['cert']}', exiting.");
    die;
}
register_shutdown_function("on_shutdown");
// Write a flag file with the PID and the port
$pid_file = "{$tmp_dir}/pid." . getmypid();
file_put_contents($pid_file, $options["port"]);
try {
    outln("Starting MLLP Server on port " . $options["port"] . " with user '" . $options["username"] . "'");
    if ($options["cert"]) {
        outln("SSL certificate: '{$options['cert']}'");
    }
    $handler = new CMLLPServer($options["url"], $options["username"], $options["password"], $options["port"], $options["cert"], $options["passphrase"]);
    $handler->run();
    quit();
} catch (Exception $e) {
    $message = $e->getMessage();
    if ($message == "Address already in use") {
        outln($message);
        quit();
    }
    $stderr = fopen("php://stderr", "w");
    fwrite($stderr, $message . PHP_EOL);
}
quit();