doutiaosu2310
2017-12-31 12:44
浏览 59
已采纳

Cron作业没有运行php脚本

I have created a cron job in my cpanel using command below:

/usr/bin/php -q /home/user/public_html/folder/subfolder/sync.php

The content of syns.php is almost like this. It works without error when I run it with the domain like domain.com/folder/subfolder/sync.php but I can not see the expected result when the cron job supposed to run which means cron job is not running the script. So can anyone tell me what might be the problem?

<?php

$dir = str_replace("public_html","", $_SERVER["DOCUMENT_ROOT"]);
$dir = $dir . "configuration.php";

if (file_exists($dir)) 
{
    require_once($dir);
    sync();
} 
else
{
    // echo ("Can't find the access data.");
}

function sync()
{
    $connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
    if(mysqli_connect_errno())
    {
        // echo ("Failed to connect the database.");
        exit();
    }
    else
    {
        if(mysqli_ping($connection))
        {
            $query = "SELECT OR UPDATE WHATEAVER FROM TABLE;";
            $result = mysqli_multi_query($connection, $query);
            if($result)
            {
                // Do stuff
            }
            else
            {
                // echo("Failed to excute the query.");
            }
        }
        else
        {
            // echo("Failed to ping the connection.");
        }
    }
    mysqli_close($connection);
}

?>

图片转代码服务由CSDN问答提供 功能建议

我使用以下命令在cpanel中创建了一个cron作业:</ p>

/ usr / bin / php -q /home/user/public_html/folder/subfolder/sync.php

nn

syns.php的内容几乎就是这样。 当我使用domain.com/folder/subfolder/sync.php这样的域运行它时,它可以正常工作,但是当cron作业应该运行时,我看不到预期的结果,这意味着cron作业没有运行脚本。 那么有谁可以告诉我可能是什么问题?</ p>

 &lt;?php 
 
 $ dir = str_replace(“public_html”,“”,$ _SERVER [“DOCUMENT_ROOT  “]); 
 $ dir = $ dir。  “configuration.php”; 
 
if(file_exists($ dir))
 {
 require_once($ dir); 
 sync(); 
} 
else 
 {
 // echo(“Can 找不到访问数据。“); 
} 
 
 
函数sync()
 {
 $ connection = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE); 
 if(mysqli_connect_errno())
 {  
 // echo(“无法连接数据库。”); 
 exit(); 
} 
 else 
 {
 if(mysqli_ping($ connection))
 {
 $ query =“  SELECT或UPDATE WHATEAVER FROM TABLE;“; 
 $ result = mysqli_multi_query($ connection,$ query); 
 if($ result)
 {
 // Do stuff 
} 
 else 
 {
  // echo(“无法执行查询。”); 
} 
} 
 else 
 {
 // echo(“无法ping通连接。”); 
} 
} 
  mysqli_close($ connection); 
} 
 
?&gt; 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题