cronjob无法运行php文件

cronjob无法运行php文件,php,crontab,Php,Crontab,我想在特定时间后在word press网站上发布相同的数据,但我有一个问题: cronjob无法运行php文件 命令: * * * * * /usr/bin/php /var/www/html/news/cronpost.php 我的代码: require 'config/config.php'; require 'config/autoload.php'; require 'IXR_Library.php'; $post = post::getInstance(); $user_websi

我想在特定时间后在word press网站上发布相同的数据,但我有一个问题:

cronjob无法运行php文件

命令:

* * * * * /usr/bin/php /var/www/html/news/cronpost.php
我的代码:

require 'config/config.php';
require 'config/autoload.php';
require 'IXR_Library.php';

$post = post::getInstance();
$user_websites = user_websites::getInstance();
$user_websites_posts = user_websites_posts::getInstance();
$spintext = spintext::getInstance();

$result = $user_websites->getuserWebsites();

foreach ($result as $row) {
    $minutes = floor((time() - strtotime($row['last_exe_time'])) / 60);
//echo $minutes . "<br>";

    if ($minutes >= $row['schedule_time']) {

        $result2 = $user_websites_posts->getPost($row['id']);

        $id = array();

        foreach ($result2 as $row2) {
            $id[] = $row2['post_id'];
        }

        $ids = implode(",", $id);

//echo $ids . "<br>";

        $row3 = $post->getRandPostId($row['local_cat_id'], $ids);

//echo $row3['id'] . "<br><br>";

        $user_websites->updateuserwebsites($row['id']);

        $user_websites_posts->addUserWebsitesPosts($row['id'], $row3['id']);

        if ($row['spin_id'] == '1') {

            $title = $spintext->api(stripslashes($row3['title']), 'Regular', 'azhar@techpointmedia.com', 'autoblogging', 'true');

            $description = $spintext->api(stripslashes($row3['description']), 'Regular', 'azhar@techpointmedia.com', 'autoblogging', 'true');

        } elseif ($row['spin_id'] == '2') {

            $title = "test title";

            $description = "test description";

        } elseif ($row['spin_id'] == '3') {

            $title = "test title";

            $description = "test description";

        } elseif ($row['spin_id'] == '4') {

            $title = "test title";

            $description = "test description";

        } elseif ($row['spin_id'] == '0') {

            $title = $row3['title'];

            $description = $row3['description'];

        }

        if (isset($row3['image']) && $row3['image'] != "") {

            $xmlrpc = $row['url'] . 'xmlrpc.php';
            $client = new IXR_Client($xmlrpc);

//$client->debug = true;

            $content = array(
                'post_status' => $row['draft_post'],
                'post_type' => 'post',
                'post_title' => $title,
                'post_content' => $description,
                'terms' => array('category' => array($row['wordpress_cat_id'])),
            );
            $params = array(0, $row['username'], $row['password'], $content);
            $client->query('wp.newPost', $params);
            $post_id = $client->getResponse();

            $content = array(
                'name' => basename($row3['image']),
                'type' => $spintext->mime_content_type($row3['image']),
                'bits' => new IXR_Base64(file_get_contents($row3['image'])),
                true,
            );
            $client->query('metaWeblog.newMediaObject', 1, $row['username'], $row['password'], $content);
            $media = $client->getResponse();
            $content = array(
                'post_status' => $row['draft_post'],
                'mt_keywords' => 'tag1, tag2, tag3',
                'wp_post_thumbnail' => $media['id'],
            );
            $client->query('metaWeblog.editPost', $post_id, $row['username'], $row['password'], $content, true);
        } else {
            $xmlrpc = $row['url'] . 'xmlrpc.php';
            $client = new IXR_Client($xmlrpc);

//$client->debug = true; //optional but useful

            $params = array(
                'post_type' => 'post',
                'post_status' => $row['draft_post'],
                'post_title' => $title,
                'post_content' => $description,
//'post_excerpt' => 'This is my test excerpt',
                'post_author' => $row['author_id'],
                'terms' => array('category' => array($row['wordpress_cat_id'])),
            );

            $res = $client->query('wp.newPost', 1, $row['username'], $row['password'], $params);
        }

    }

}
需要'config/config.php';
需要'config/autoload.php';
需要“IXR_Library.php”;
$post=post::getInstance();
$user\u websites=user\u websites::getInstance();
$user\u websites\u posts=user\u websites\u posts::getInstance();
$spintext=spintext::getInstance();
$result=$user_websites->getuserWebsites();
foreach($结果为$行){
$minutes=floor((time()-strotime($row['last\u exe\u time']))/60);
//回声$minutes.“
”; 如果($minutes>=$row['schedule\u time'])){ $result2=$user\u websites\u posts->getPost($row['id']); $id=array(); foreach($result2作为$row2){ $id[]=$row2['post_id']; } $id=内爆(“,”,$id); //echo$id。“
”; $row3=$post->getRandPostId($row['local\u cat\u id',$id); //echo$row3['id']。“

”; $user_websites->updateuserwebsites($row['id']); $user\u websites\u posts->addUserWebsitesPosts($row['id'],$row3['id']); 如果($row['spin_id']=='1'){ $title=$spintext->api(带斜杠($row3['title']),'Regular','azhar@techpointmedia.com'、'autobloging'、'true'); $description=$spintext->api(带斜杠($row3['description']),'Regular','azhar@techpointmedia.com'、'autobloging'、'true'); }elseif($row['spin_id']=='2'){ $title=“测试标题”; $description=“测试描述”; }elseif($row['spin_id']=='3'){ $title=“测试标题”; $description=“测试描述”; }elseif($row['spin_id']=='4'){ $title=“测试标题”; $description=“测试描述”; }elseif($row['spin_id']=='0'){ $title=$row3['title']; $description=$row3['description']; } 如果(isset($row3['image'])和&$row3['image']!=“”){ $xmlrpc=$row['url'.'xmlrpc.php'; $client=新的IXR_客户端($xmlrpc); //$client->debug=true; $content=array( “发布状态”=>$row[“草稿发布”], “post_type”=>“post”, “post_title”=>$title, “发布内容”=>$description, 'terms'=>array('category'=>array($row['wordpress\u cat\u id')), ); $params=array(0,$row['username'],$row['password'],$content); $client->query('wp.newPost',$params); $post_id=$client->getResponse(); $content=array( 'name'=>basename($row3['image']), 'type'=>$spintext->mime\u content\u type($row3['image']), 'bits'=>新的IXR_Base64(文件获取内容($row3['image']), 是的, ); $client->query('metaWeblog.newMediaObject',1,$row['username'],$row['password'],$content); $media=$client->getResponse(); $content=array( “发布状态”=>$row[“草稿发布”], ‘mt_关键字’=>‘tag1、tag2、tag3’, “wp_post_缩略图”=>$media['id'], ); $client->query($metaWeblog.editPost',$post_id,$row['username'],$row['password'],$content,true); }否则{ $xmlrpc=$row['url'.'xmlrpc.php'; $client=新的IXR_客户端($xmlrpc); //$client->debug=true;//可选但有用 $params=数组( “post_type”=>“post”, “发布状态”=>$row[“草稿发布”], “post_title”=>$title, “发布内容”=>$description, //“post_摘录”=>“这是我的测试摘录”, 'post_author'=>$row['author_id'], 'terms'=>array('category'=>array($row['wordpress\u cat\u id')), ); $res=$client->query('wp.newPost',1,$row['username'],$row['password'],$params); } } }
如果我用此代码替换上述代码,cronjob将运行它:

class DBConnect {
function Connect() {
$root = "root";
$pass = "12345";
return $db = new PDO('mysql:host=localhost;dbname=testing', $root, $pass);
}
}

class operations {

// for single instance
protected static $instance = null;
protected $pdo = null;

// Constructor : database connection
public function __construct() {

try {
$con = new DBConnect();
$this->pdo = $con->Connect();
//echo "connected";
} catch (PDOException $e) {
echo $e->getMessage();
}
}

// Getting single instance
public static function getInstance() {
if (!isset(static::$instance)) {
static::$instance = new static;
}
return static::$instance;
}

public function insertRecord($tableName, $cols, $values) {

try {
$number_of_rows = 0;

$sql = "INSERT INTO `$tableName`($cols) VALUES($values)";

//echo $sql;

//exit();

$count = $this->pdo->exec($sql);

} catch (PDOException $e) {
echo $e->getMessage();
}

if ($count > 0) {
return true;
} else {
return false;
}
}

public function selectRecords($tableName, $select = '*', $where = '1') {
try {

$sql = "SELECT $select FROM $tableName WHERE $where";
$stmt = $this->pdo->query($sql);
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);

} catch (PDOException $e) {
echo $e->getMessage();
}

return $row;
}

public function updateRecord($tableName, $fields, $where) {

try {
$number_of_rows = 0;

$sql = "UPDATE `$tableName` SET $fields WHERE $where";

//echo $sql;
//exit();

$count = $this->pdo->exec($sql);

} catch (PDOException $e) {
echo $e->getMessage();
}

if ($count > 0) {
return true;
} else {
return false;
}
}

}

$show = operations::getInstance();

$result = $show->selectRecords("test2");

//$post->insertRecord("test", "message", "'new message'");
//echo "abc";

foreach ($result as $row) {
echo $row['message'] . "<br>";
$minutes = round(abs(time() - strtotime($row['last_exe_time'])) / 60, 0);
echo $minutes . " min<br><br>";

if ($minutes >= $row['tm'] && $minutes > 0) {

$show->insertRecord("test", "message", "'$row[message]'");

$show->updateRecord("test2", "last_exe_time=CURTIME()", "id=$row[id]");

}
} 
classdbconnect{
函数连接(){
$root=“root”;
$pass=“12345”;
返回$db=newpdo('mysql:host=localhost;dbname=testing',$root,$pass);
}
}
班级作业{
//例如
受保护的静态$instance=null;
受保护$pdo=null;
//构造函数:数据库连接
公共函数构造(){
试一试{
$con=新的数据库连接();
$this->pdo=$con->Connect();
//回声“连接”;
}捕获(PDO$e){
echo$e->getMessage();
}
}
//获取单个实例
公共静态函数getInstance(){
if(!isset(静态::$instance)){
静态::$instance=newstatic;
}
返回静态::$instance;
}
公共函数insertRecord($tableName、$cols、$values){
试一试{
$number_of_行=0;
$sql=“插入到“$tableName”($cols)值($VALUES)”中;
//echo$sql;
//退出();
$count=$this->pdo->exec($sql);
}捕获(PDO$e){
echo$e->getMessage();
}
如果($count>0){
返回true;
}否则{
返回false;
}
}
公共函数selectRecords($tableName,$select='*',$where='1')){
试一试{
$sql=“选择$SELECT FROM$tableName WHERE$WHERE”;
$stmt=$this->pdo->query($sql);
$row=$stmt->fetchAll(PDO::FETCH_ASSOC);
}捕获(PDO$e){
echo$e->getMessage();
}
返回$row;
}
公共函数更新记录($tableName,$fields,$where){
试一试{
$number_of_行=0;
$sql=“UPDATE`$tableName`设置$fields WHERE$WHERE”;
//echo$sql;
//退出();
$count=$this->pdo->exec($sql);
}捕获(PDO$e){
echo$e->getMessage();
}
如果($count>0){
返回true;
}否则{
返回false;
}
}
}
$show=operations::getInstance();
$result=$show->selectRecords(“test2”);
//$post->insertRecord(“测试”、“消息”、“新消息”);
//呼应“abc”;
foreach($结果为$行){
echo$row['message']。“
”; $minutes=round(abs(time()-strotime($row['last_exe_time']))/60,0); echo$minutes.“min

”; 如果($minutes>=$row['tm']&&$minutes>0){ $