Skip to content
PHP Logo

How can PHP scripts be triggered to check for the presence of .json files in a folder at irregular intervals?

To trigger PHP scripts to check for the presence of .json files in a folder at irregular intervals, you can use a combination of a cron job and a PHP script. The cron job can be scheduled to run the PHP script at the desired intervals. Within the PHP script, you can use functions like `scandir()` to scan the folder for .json files and perform any necessary actions based on their presence.

php
<?php
// Check for .json files in a folder
$folder = '/path/to/folder/';
$files = scandir($folder);

foreach ($files as $file) {
    if (pathinfo($file, PATHINFO_EXTENSION) == 'json') {
        // Perform actions based on the presence of .json files
        echo "Found JSON file: $file\n";
    }
}
?>