【发布时间】:2017-05-23 10:01:18
【问题描述】:
我每分钟运行一个 cron 作业,它运行一个循环;我将每个循环的结果输出到日志文件中。这个函数在一个类中,并且在手动调用该函数时运行得非常好。但是,当通过 cron 作业调用该函数时,file_put_contents() 什么都不做(该函数的其余部分工作正常,即表插入)。
protected function updatePair( $time, $pair_reference, $price, $exchange_id ) {
$exchange_reference = get_field('reference', $exchange_id);
global $wpdb;
$table = $wpdb->prefix . $pair_reference . '_' . $exchange_reference;
// Insert time and price into table
$wpdb->insert($table, array(
"time" => $time,
"price" => $price
));
//Write action to txt log
$log = "Pair: ".$pair_reference.' - '.date("F j, Y, g:i a").PHP_EOL.
"Attempt: Finished".PHP_EOL.
"-------------------------".PHP_EOL;
//-
file_put_contents('log/exchange.txt', $log, FILE_APPEND);
}
【问题讨论】:
-
您是否有写入日志文件夹的权限。如果它没有像这样更改权限,请检查您的权限 chmod 0777 -R log/
-
该函数在手动调用时写入日志文件,即 $class->updatePair( ... ) 但不是在 cron 决定这样做时。 cron 需要不同的权限吗?请原谅新手的问题。
-
你需要给apache用户权限
-
没有这样的运气,权限等都按规定设置。
-
你能不能也显示你的 crontab 调用