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

posted @ 2019-03-07 15:03  终究是乌云遮了天  阅读(409)  评论(0编辑  收藏  举报