I am running a cron job every minute which runs a loop; I am outputting the results from each loop into a log file. This function is inside a class, and runs absolutely fine when the function is called manually. However, when the function is called via a cron job, file_put_contents() does nothing (the rest of this function works fine i.e. the table insertion).
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);
}