cronjob n'a pas pu lancer un file php

je veux afficher les mêmes données sur le site de presse de mot après un time précis, mais j'ai un problème:

cronjob n'a pas pu lancer un file php

order:

* * * * * /usr/bin/php /var/www/html/news/cronpost.php 

mon code:

 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(ssortingpslashes($row3['title']), 'Regular', 'azhar@techpointmedia.com', 'autoblogging', 'true'); $description = $spintext->api(ssortingpslashes($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); } } } 

Si je remplace le code ci-dessus par ce code, cronjob l'exécute:

 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]"); } } 

dites-moi pourquoi Cronjob n'a pas pu exécuter mon premier code.

Tout d'abord, essayez d'exécuter /usr/bin/php /var/www/html/news/cronpost.php dans la console, si elle s'exécute, vous pouvez essayer d'utiliser le script shell. Créez un file de script shell. exemple /root/cron.sh avec le contenu /usr/bin/php /var/www/html/news/cronpost.php Ensuite, utilisez chmod + x pour votre script. Enfin, vous créez un cronjob comme ça

* * * * * /root/cron.sh