What are the potential security risks of using PHP for automated tasks like cron jobs?

One potential security risk of using PHP for automated tasks like cron jobs is the exposure of sensitive information, such as database credentials, in plain text within the PHP script. To mitigate this risk, it is recommended to store sensitive information in environment variables and access them within the PHP script.

// Use environment variables to store sensitive information
$db_host = getenv('DB_HOST');
$db_user = getenv('DB_USER');
$db_pass = getenv('DB_PASS');
$db_name = getenv('DB_NAME');

// Connect to the database using the environment variables
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);

// Perform automated tasks using the database connection
// ...