2016-09-16 179 views
1

我得到以下解决方案,每1分钟执行一次php脚本,但它不工作。你会发现错误或任何新的解决方案?每1分钟运行一次php脚本,而不是cron作业

<?php 

    while (true) 
    { 

    echo "hi"; 
    sleep(60)); 
    } 
?> 
+0

注意:您只需要使用'睡眠($间隔* 60);'而不是'睡眠($ interval * 60-(time() - $ now));'as time() - $ now'将始终为'0'。 – maxhb

+0

什么不行?你有错误吗,它会停止运行吗?还有其他的东西吗? – Blaatpraat

+0

你是什么意思不起作用?对我来说,它每隔1分钟循环遍历循环 – Matthieu

回答

1

你可以用AJAX做 jQuery的AJAX文档:http://api.jquery.com/jquery.ajax/

<!doctype html> 
 
<html> 
 
\t <head> 
 
\t \t <meta charset="utf-8"> 
 
\t \t <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script> 
 
\t \t <title>asd</title> 
 
\t </head> 
 
\t <script type="text/javascript"> 
 
\t function theAjaxCall(){ 
 
\t \t $.ajax({ 
 
\t \t \t url: 'your_php_file.php',// set your config 
 
\t \t \t data: {action: 'test'}, 
 
\t \t \t type: 'post', 
 
\t \t \t success: function(output) { 
 
\t \t \t \t $("body").append(output); 
 
\t \t \t } 
 
\t \t }); 
 
\t } 
 
\t $(document).ready(function(){ 
 
\t \t setInterval(theAjaxCall, 60000);//every 1 min 
 
\t }); 
 
\t </script> 
 
\t <body> 
 
\t \t 
 
\t </body> 
 
</html>

+0

请将setTimeout()更改为setInterval()..它工作正常..感谢您的回答:) ..做这个改变,我会推测答案。 –

+0

你对吧:) –

相关问题