PHP cron job doesn't start log via file_put_contents ()
I run a cron job every minute which starts a loop; I am dumping the results from each loop to a log file. This function is inside the class and works absolutely fine when the function is called manually. However, when the function is called with a cron job, file_put_contents () does nothing (the rest of this function works fine, i.e. insert the table).
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);
}
+3
source to share