Hi i want to run my php file every 5 minutes without page load using ajax. also so content based on fromtime to totime
require_once("config.php");
$sql = "SELECT * FROM schedule where status='1'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "Content: " . $row["content"] . "<br />";
echo "Content: " . $row["fromtime"] . "<br />";
echo $date = time();
$test = strtotime($row["fromtime"]);
echo "<br />";
echo $test;
if ($date > $test) {
echo "Success";
}
else {
echo "Fail";
}
}
} else {
echo "0 results";
}
$conn->close();
Assuming you have server access you'll need to set up a crontab
. For every 5 mins it'll be
*/5 * * * * php /path/to/php/script.php
Noticed updated for Ajax. Use this solution if you want to run it without the page being open.
Also noticed you want to parse variables, php does support that and parsing them in is like so:
*/5 * * * * php /path/to/php/script.php var1 var2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.