Cpanel Cron作业未完全运行我的php代码

Cpanel Cron作业未完全运行我的php代码,php,mysql,curl,cron,Php,Mysql,Curl,Cron,我有一个cron作业设置来运行一个php脚本,该脚本将抓取一个站点,获取数据并放入mysql数据库。如果我只是导航到url,代码工作正常。对于每个新记录,我都会收到“New Record Created Successfully”(新记录创建成功)消息,这些记录都在我的数据库中。但是当我的cron运行它时,我只得到数据库连接的“connectedsuccessfully”消息。似乎没有别的办法。我的参赛脚本如下 <?php //nba spider require 'simple_ht

我有一个cron作业设置来运行一个php脚本,该脚本将抓取一个站点,获取数据并放入mysql数据库。如果我只是导航到url,代码工作正常。对于每个新记录,我都会收到“New Record Created Successfully”(新记录创建成功)消息,这些记录都在我的数据库中。但是当我的cron运行它时,我只得到数据库连接的“connectedsuccessfully”消息。似乎没有别的办法。我的参赛脚本如下

<?php

//nba spider

require 'simple_html_dom.php';

//Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777
function login($url,$data){
    $fp = fopen("cookie.txt", "w");
    fclose($fp);
    $login = curl_init();
    curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($login, CURLOPT_TIMEOUT, 40000);
    curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($login, CURLOPT_URL, $url);
    curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($login, CURLOPT_POST, TRUE);
    curl_setopt($login, CURLOPT_POSTFIELDS, $data);
    ob_start();
    return curl_exec ($login);
    ob_end_clean();
    curl_close ($login);
    unset($login);    
}                  

function grab_page($site){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_URL, $site);
    ob_start();
    return curl_exec ($ch);
    ob_end_clean();
    curl_close ($ch);
}

function post_data($site,$data){
    $datapost = curl_init();
    $headers = array("Expect:");

    curl_setopt($datapost, CURLOPT_URL, $site);
    curl_setopt($datapost, CURLOPT_TIMEOUT, 40000);
    curl_setopt($datapost, CURLOPT_HEADER, TRUE);
    curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($datapost, CURLOPT_POST, TRUE);
    curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
    curl_setopt($datapost, CURLOPT_RETURNTRANSFER, 1); // return the output in string format
    curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
    ob_start();
    return curl_exec ($datapost);
    ob_end_clean();
    curl_close ($datapost);
    unset($datapost);    
}



login("#","#");
$post = post_data("#","#");

$html = str_get_html($post);
//print $post;


$servername = "localhost";
$username = "#";
$password = "#";
$dbname = "#";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";


foreach ($html->find('.teams_betting_options_advance') as $table) 
{
    //echo $table->innertext.'<br>';
    //$date = $table->find('.opt_advance_date');
    //echo $date.'<br>';

    // game date and time
    $date = $table->find('.opt_advance_date', 0)->innertext;

    //top line
    $team_top = $table->find('span[data-language]', 0)->innertext;
    $team_top_spread = $table->find('option[selected]', 0)->innertext;
    $team_top_spread =substr($team_top_spread, 0, -10);
    $team_top_money_line = substr($table->find('.tbl_betAmount_td', 1)->innertext, -4);
    $both_over = substr($table->find('option[selected]', 1)->innertext, 1, -10);

    //bottom line
    $team_bottom = $table->find('span[data-language]', 1)->innertext;
    $team_bottom = trim($team_bottom);
    $team_bottom_spread = $table->find('option[selected]', 2)->innertext;
    $team_bottom_spread =substr($team_bottom_spread, 0, -10);
    $team_bottom_money_line = substr($table->find('.tbl_betAmount_td', 6)->innertext, -4);
    $both_under = substr($table->find('option[selected]', 3)->innertext, 1, -10);


    //date time to mysql format
   $date = preg_replace("/&#?[a-z0-9]+;/i"," ",$date);
   $date = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date)));





    //insert each into database
   $sql = 'INSERT INTO nba (date_time, team_top, team_top_spread, team_top_money_line, both_over, team_bottom, team_bottom_spread, team_bottom_money_line, both_under)
   VALUES ("'.$date.'", "'.$team_top.'", "'.$team_top_spread.'", "'.$team_top_money_line.'", "'.$both_over.'", "'.$team_bottom.'", "'.$team_bottom_spread.'", "'.$team_bottom_money_line.'", "'.$both_under.'")';

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}



}

$conn->close();
?>

听起来可能是权限问题。检查运行cron作业的用户