When should you use require() instead of include() in PHP?

You should use require() instead of include() in PHP when you want to include a file that is essential for your script to run. If the file cannot be included, require() will produce a fatal error and stop the script execution, while include() will only produce a warning and continue execution. This ensures that the necessary file is loaded and the script does not continue if it is not available.

<?php
require('essential_file.php');

// Rest of your PHP code
?>