How can PHP scripts be scheduled to run at specific times for tasks like deleting expired listings?

To schedule PHP scripts to run at specific times for tasks like deleting expired listings, you can use a cron job on your server. This allows you to set a schedule for when the PHP script should run automatically. Within the PHP script, you can write the logic to check for and delete expired listings based on your requirements.

// Example PHP script for deleting expired listings
// This script can be scheduled to run using a cron job

// Connect to database
$pdo = new PDO('mysql:host=localhost;dbname=your_database', 'username', 'password');

// Delete expired listings
$deleteExpiredListings = $pdo->prepare("DELETE FROM listings WHERE expiration_date < NOW()");
$deleteExpiredListings->execute();