Exemple #1
0
 * shutdown. In this way we can spawn a process in the ant file and kill the
 * process when deleting the lock file.
 */
$service = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null;
$action = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : null;
$iniFile = DIRECTORY_SEPARATOR === '\\' ? 'build-win.properties' : 'build-default.properties';
$config = parse_ini_file($iniFile);
// we are currently in the build dir we must change to the public dir to start
// a service
chdir(__DIR__ . '/../public');
$commands = ['webserver' => $config['php'] . ' -S 127.0.0.1:8008 server.php', 'webdriver' => $config['nodejs'] . ' fusio/node_modules/protractor/bin/webdriver-manager start'];
if (isset($commands[$service])) {
    if ($action == 'stop') {
        stopProcess($service);
    } else {
        startProcess($service, $commands[$service]);
    }
} else {
    echo 'Unknown service' . "\n";
    exit(1);
}
function startProcess($name, $cmd)
{
    echo 'Start ' . $name . ' (' . $cmd . ')' . "\n";
    $process = proc_open($cmd, array(), $pipes);
    $status = proc_get_status($process);
    $pid = $status['pid'];
    $file = __DIR__ . '/../cache/' . $name . '.lock';
    file_put_contents($file, $pid);
}
function stopProcess($name)
Exemple #2
0
        echo $msg;
    } else {
        //linux环境写入日志
        $dir = "/data/logs/autoStockUp/";
        if (!is_dir($dir)) {
            @mkdir($dir, 0777, true);
        }
        file_put_contents($dir . date("Y-m") . '.log', $msg, FILE_APPEND);
    }
}
/**
 * Send a POST requst using cURL
 * @param string $url to request
 * @param array $post values to send
 * @param array $options for cURL
 * @return string
 */
function curlPost($url, $post = null, array $options = array())
{
    $defaults = array(CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => $url, CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 40, CURLOPT_POSTFIELDS => $post);
    $ch = curl_init();
    curl_setopt_array($ch, $options + $defaults);
    if (!($result = curl_exec($ch))) {
        trigger_error(curl_error($ch));
    }
    curl_close($ch);
    return json_decode($result, true);
}
$db = Yii::app()->sdb;
startProcess($db);
    //当天凌晨的时间戳
    $todayZoneTime = strtotime(date('Y-m-d'), $time);
    //每分钟的时间戳
    $minuteTime = strtotime(date('Y-m-d H:i:00'), $time);
    if ($time - $minuteTime < 5 && $minuteCount == 0) {
        startProcess(1, '/var/www/html/adsb/adsb/deviceexception.php');
        $minuteCount = 5;
    }
    if ($time - $todayZoneTime < 5 && $todayZoneCount == 0) {
        startProcess(1, '/var/www/html/adsb/adsb/tasks/synchronousAirports.php');
        startProcess(1, '/var/www/html/adsb/adsb/aircraftnumbersync.php');
        $todayZoneTime = 5;
    }
    //每隔2分钟启动一次
    if ($time - $time5 >= 120) {
        startProcess(5, '/var/www/html/adsb/adsb/tasks/indexEstimatedArrive.php');
        $time5 = $time;
    }
    if ($minuteCount > 0) {
        $minuteCount--;
    }
    if ($todayZoneCount > 0) {
        $todayZoneCount--;
    }
    sleep(1);
}
//开启一个进程
function startProcess($limit, $processPath)
{
    $number = 1;
    $cmd = popen("ps -ef | grep \"" . $processPath . "\" | grep -v grep | wc -l", "r");
Exemple #4
0
function mainContent()
{
    global $action;
    switch ($action) {
        case "startProcess":
            startProcess();
            break;
        case "performProcess":
            performProcess();
            break;
    }
}