gpt4 book ai didi

PHP Cron 作业不执行

转载 作者:太空宇宙 更新时间:2023-11-04 11:10:02 25 4
gpt4 key购买 nike

<分区>

我正在尝试在我的 Linux 服务器上设置一个 cron 作业。

我有以下代码

*/1 * * * * root php -f /var/www/html/includes/cron/cron.inc.a.php &> dev/php.log

cron 作业要调用的文件从另一台服务器获取心跳响应。

<?php

$l = new MySQLi();

$l->connect(blah);

$q = $l->query("SELECT * FROM `tbl_latency_stats`");

set_include_path('/var/www/html/includes/');

include("ping/ping.php");

$host = '<IP ADDRESS>';

$ping = new Ping($host);

$latency = $ping->ping();

if (!is_bool($latency)){
if(is_float($latency) || is_string($latency)) {
if(is_string($latency)){
$s = split(".", $latency);
if($s[0] >= 100){
$response_array['status'] = "success";
$response_array['state'] = "WARNING";
$response_array['timedate'] = date("Y-m-d H:i:s");
$response_array['response'] = "High Latency";
$response_array['ping'] = "$latency";
$response_array['message'] = "null";
}else{
$response_array['status'] = "success";
$response_array['state'] = "UP";
$response_array['timedate'] = date("Y-m-d H:i:s");
$response_array['response'] = "LIVE";
$response_array['ping'] = "$latency";
$response_array['message'] = "null";
}
}elseif(is_float($latency)){
if($latency >= 100){
$response_array['status'] = "success";
$response_array['state'] = "WARNING";
$response_array['timedate'] = date("Y-m-d H:i:s");
$response_array['response'] = "High Latency";
$response_array['ping'] = "$latency";
$response_array['message'] = "null";
}else{
$response_array['status'] = "success";
$response_array['state'] = "UP";
$response_array['timedate'] = date("Y-m-d H:i:s");
$response_array['response'] = "LIVE";
$response_array['ping'] = "$latency";
$response_array['message'] = "null";
}
}
}else{
$response_array['status'] = "error";
$response_array['state'] = "UNKONWN";
$response_array['timedate'] = date("Y-m-d H:i:s");
$response_array['message'] = "Unexpected Response!";
$response_array['response'] = "$latency";
$response_array['ping'] = "null";
}
}else {
$response_array['status'] = "error";
$response_array['state'] = "DOWN";
$response_array['timedate'] = date("Y-m-d H:i:s");
$response_array['message'] = "Request Unreachable!";
$response_array['response'] = "$latency";
$response_array['ping'] = "null";
}

$q = $l->query("INSERT INTO `enigmaStat`.`tbl_latency_stats` (`latency_stat_id` ,`latency_stat_date_time` ,`latency_stat_status` ,`latency_stat_response` ,`latency_stat_latency_value` ,`latency_stat_user_text`)VALUES ('' , '".$response_array['timedate']."' , '".$response_array['state']."', '".$response_array['response']."', '".$response_array['ping']."', '".$response_array['message']."')");


?>

但是没有插入。我已经从网站路径运行文件并通过命令行手动运行,如下所示:

php -f /var/www/html/includes/cron/cron.inc.a.php

然后插入数据库。

我是服务器配置等方面的新手,所以如果这不够详细,我深表歉意,我很乐意添加任何必要的细节来帮助解决问题。

谢谢。


编辑

按照我试过的维基:

env -i sh -c 'php -f /var/www/html/includes/cron/cron.inc.a.php'

它可以工作并插入到数据库中。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com