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

  • 相关阅读:
    【leetcode】Maximum Subarray
    【USACO】
    【leetcode】Remove Duplicates from Sorted Array
    【leetcode】Path Sum II
    【leetcode】Swap Nodes in Pairs
    【leetcode】Word Ladder
    【leetcode】Copy List with Random Pointer
    【leetcode】Longest Palindromic Substring
    #ifdef #endif #if #endif
    tar [options] [list of file]
  • 原文地址:https://www.cnblogs.com/CWQPHP/p/10489716.html
Copyright © 2011-2022 走看看