zoukankan      html  css  js  c++  java
  • 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];// 时间间隔;

  • 相关阅读:
    gym 101480 Problem C: Cow Confinement 题解
    Uva 1072 Huffman Codes 题解
    NERC 2015 Hypercube 题解
    ACM ICPC 2017 WF Problem J Son of Pipe Stream题解
    CF Round # 295 (Div. 1)题解
    CF 1444 D Rectangular Polyline 题解
    BZOJ3308 九月的咖啡店
    BZOJ4025 二分图
    BZOJ4000 [TJOI2015]棋盘
    BZOJ3999 [TJOI2015]旅游
  • 原文地址:https://www.cnblogs.com/CWQPHP/p/10489716.html
Copyright © 2011-2022 走看看