我想問如何使一個PHP腳本回聲存儲在數據庫中的數據的id重複本身特定的時間後,例如2分鐘後,我不想使用一個cron工作或另一個scheduler.Just PHP或JavaScript實現。預先感謝..autorepeat一個PHP腳本
1
A
回答
3
我已經做了類似的這個腳本。當用戶在頁面上時,它每2分鐘運行scriptToRun.php
。
function changeFeedAddress() {
$.ajax({
type: 'get',
url: 'scriptToRun.php',
success: function(txt) {
// do something with the new RSS feed ID here
}
});
}
setInterval(changeFeedAddress,120000); // 2 MINUTES
1
候補@JMC創意(自足例如的緣故):
<?php
// check if the $.post below is calling this script
if (isset($_POST['ajax']))
{
// $data = /*Retrieve the id in the database*/;
// ---vvvv---remove---vvvv---
// Example Data for test purposes
$data = rand(1,9999);
// End Example Data
// ---^^^^---remove---^^^^---
// output the new ID to the page so the $.post can see it
echo $data;
exit; // and stop processing
}
?>
<html>
<head>
<title>Demo Update</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
// assign a timeout for this script
var timeout = 2 * 60000; // 2 minutes
// create a function we can call over and over to fetch the ID
function updateDBValue(){
// call this same script and retrieve an "id from the database" (see top of page)
$.post('<?php echo $_SERVER['PHP_SELF']; ?>',{ajax:true},function(data){
// 'data' now contains the new ID. For example's sake, place the value
// in to an input field (as shown below)
$('#db-value').val(data);
// set a timer to re-call this function again
setTimeout(updateDBValue,timeout);
});
}
// call the function initially
updateDBValue();
});
</script>
</head>
<body style="text-align:center;">
<div style="margin: 0 auto;border:1px solid #000;display:block;width:150px;height:50px;">
DB Value:<br />
<input type="text" id="db-value" style="text-align:center;" />
</div>
</body>
</head>
1
爲什麼不這樣做呢?
<?php
header('refresh: 600; url=http://www.yourhost.com/yourscript.php');
//script here
?>
如果您從腳本中隨機生成您的ID ...這將工作正常。該頁面將每10分鐘刷新一次。
相關問題
- 1. 一個PHP腳本中phing
- 2. 編寫一個php腳本
- 3. daemonizing一個PHP腳本
- 4. 幫助一個PHP腳本
- 5. 從另一個腳本請求一個PHP腳本,並移動
- 6. 從另一個PHP腳本執行PHP腳本
- 7. PHP腳本能否啓動另一個PHP腳本並退出?
- 8. 如何通過我的PHP腳本運行一個PHP腳本?
- 9. 如何訪問PHP腳本中的另一個PHP腳本?
- 10. 如何從另一個PHP腳本調用PHP腳本?
- 11. 從另一個PHP腳本訪問受限制的PHP腳本
- 12. 如何讓php腳本運行另一個php腳本
- 13. 從一個PHP腳本運行PHP腳本而不會阻塞
- 14. 從另一個外部php腳本運行外部php腳本
- 15. PHP重現一個JS腳本(轉換爲PHP腳本)
- 16. Nginx/PHP-FPM exec另一個php腳本
- 17. 在另一個php腳本中執行一個php腳本(帶參數)
- 18. 如何從另一個php腳本中殺死一個php腳本?
- 19. PHP腳本在一定時間後觸發另一個腳本
- 20. 一個三個PHP腳本,可能嗎?
- 21. 一個php腳本的用戶輸入傳遞給另一個php,而無需修改第一個php腳本
- 22. 每個「x」秒內執行另一個php腳本中的php腳本
- 23. PHP/Ajax/jQuery - 將一個jQuery值傳遞給一個PHP腳本
- 24. 每小時添加一個PHP腳本
- 25. PHP - 一次執行多個腳本(AJAX)
- 26. 一個網站的代理php腳本
- 27. 讓PHP運行一個Python腳本
- 28. 一個PHP腳本中的IF語句
- 29. 如何執行一個php腳本?
- 30. 發送數據到一個PHP腳本
你爲什麼不想使用cron作業? – DTest 2011-01-12 00:33:42
如果你只是需要頁面自動重新加載:[元刷新](http://en.wikipedia.org/wiki/Meta_refresh)。如果這不是你所需要的,請澄清你的問題。 – drudge 2011-01-12 00:35:56
老實說,我不知道如何使用它。但這不是原因!!!我更喜歡在PHP或JavaScript中實現... – olaf36 2011-01-12 00:36:38