• liunx运行php脚本


    #!/usr/bin/php -q
    <?php

    $config = include(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'database.php');//数据库配置

    //数据库连接
    function getDBConn($dbname = "api")
    {
    $config = include(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'database.php');
    $dbh = new PDO('mysql:host=localhost;port=3306;dbname=' . $dbname . '', $config['default']['username'], $config['default']['password']);
    $dbh->query("SET NAMES UTF8");
    return $dbh;
    }



    $db = getDBConn($dbname = "api");
    
    
    $time = time() - 10;
    $list = $db->query("select * from arrange where status= 0 and uptime<=" . $time . " limit 5")->fetchAll(PDO::FETCH_ASSOC);



    $data1 = array();
    foreach ($list as $list_key => $list_value) {
    $task = explode("-", $list_value['task']);
    unset($list_value['status']);
    $data1[$task['1']][] = $list_value;
    }
     

     脚本可触发脚本执行脚本

    #!/usr/bin/php -q
    <?php
    $cmd = "/usr/bin/php -q in.php";
    pclose(popen($cmd.' > /dev/null &', 'r'));// 触发autocall.php脚本

    //脚本名+空格+参数+空格+参数

    $cmd = "/usr/bin/php  ".MODULE_PATH."controller".DS."common".DS."getdata.php ".$getdata_link." ".$gettime

    pclose(popen($cmd.' > /dev/null &', 'r'));// 触发脚本

    getdata.php

    $argv[0]为触发getdata.php的脚本名

    $url=$argv[1];// 获取数据地址;
    $interval=$argv[2];// 时间间隔;

  • 相关阅读:
    hdu 1163 Eddy's digital Roots (数学)
    hdu 2546 饭卡 (01背包)
    hdu 1059 Dividing(多重DP)
    晚霞
    最佳学习方法
    [备忘]求两数最大公约,最小公倍数
    不眠的夏夜
    超女唱《八荣八耻》:好完美的恶搞啊
    公司展会上的德国MM
    我玩游戏
  • 原文地址:https://www.cnblogs.com/CWQPHP/p/10489716.html
Copyright © 2020-2023  润新知