What is the potential issue with using fopen and fclose in a PHP cronjob to execute a file every 5 minutes?

Using fopen and fclose in a PHP cronjob to execute a file every 5 minutes can potentially lead to file locking issues if the file is not closed properly. To solve this problem, it is recommended to use file_get_contents and file_put_contents functions instead, as they do not require manual opening and closing of files.

<?php
// Read the contents of the file
$file_contents = file_get_contents('example.txt');

// Modify the contents as needed
$file_contents .= "New content added at " . date('Y-m-d H:i:s') . PHP_EOL;

// Write the modified contents back to the file
file_put_contents('example.txt', $file_contents);
?>