您可以创建一个html页面并在浏览器上打开它.javascript setInterval函数将调用指定的句点.
以下是执行此操作的代码.指定间隔(例如,每5秒运行一次)
<html>
<head>
<title>Cron</title>
</head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<body>
<h1>Cron page</h1>
<script type="text/javascript">
setInterval(function(){
$.get('http://localhost/test/test.php', function(data) {
console.log(data);
});
}, 5000);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
注意:要避免CORS,您应该从同一主机调用ajax或从服务器端允许CORS.
小智 5
你可以运行这个:
set_time_limit(0);
ignore_user_abort(true);
while (1)
{
//your code here....
sleep($timetowait);
}
Run Code Online (Sandbox Code Playgroud)
您可以关闭浏览器脚本将继续
set_time_limit(0); 让您的脚本不受时间限制地工作
sleep($timetowait); 确定在执行下一个 while() 循环之前等待的时间
ignore_user_abort(true); 即使浏览器关闭也让脚本继续
while(1) 是一个无限循环,因此在您退出 wamp 之前这将永远不会停止。