• 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];// 时间间隔;

  • 相关阅读:
    扩展欧几里得算法
    Warshall算法
    自己的博客
    使用forever运行web项目
    C#语言基础 Main 函数中的输出输入
    新手第一天学习 C#语言(进制互换)
    Django + Uwsgi + Nginx 实现生产环境部署1
    基于Flask的web微信
    python保存文件UnicodeEncodeError以及reload(sys)后print失效问题
    轮询/长轮询
  • 原文地址:https://www.cnblogs.com/CWQPHP/p/10489716.html
Copyright © 2020-2023  润新知