#! /usr/bin/php query($q); $entries = array(); // Check if there are any results if ($results) { // Fetch and display each row while ($row = $results->fetchArray(SQLITE3_ASSOC)) { if (strpos($row['key'], "/MediaCache/") === 0) { $entries[$row['value']]['url'] = str_replace('/MediaCache/', '', $row['key']); } else{ foreach ($endings as $ending) { if (substr($row['key'], -strlen($ending)) === $ending) { $k = explode('/', $row['key']); $k = $k[1]; $entries[$k][$ending] = trim($row['value']); break; // Stop the loop if a match is found } } } } } else { echo "No results found or error in query execution\n"; } foreach($entries as $entry){ if ($entry['actual_expires'] < $time_back) { $ctr = "/usr/sbin/asterisk -rx'media cache delete {$entry['url']}'"; system($ctr); usleep(100000); echo $ctr."\n"; } } } catch (Exception $e) { echo "Unable to open database: " . $e->getMessage(); } $q = "select * from astdb limit 10;"; // Your database operations go here // Close the database connection $db->close(); ?>