php - Execute query after 1 hour -
every hour want recent items added table. table populated source, , need track last id received , new items added since.
$check5 = "select * media_ids"; $rs5 = mysqli_query($con,$check5); if(mysqli_num_rows($rs5)==1) { $row = mysqli_fetch_assoc($rs5); $media_id=$row['media_id']; } // execute query
- you need create cronjob runs hourly.
crontab -e
, add 0 * * * * php /path/to/script/script.php
- add column table called
created
, set typetimestamp
set default valuecurrent_timestamp
3a. -- fetch in last hour script.php should like:
<?php $current = time() - 3600; $currentmediaquery = "select media_id media_ids created > {$current}" $mediaquery = mysqli_query($con, $currentmediaquery); if (mysqli_num_rows($mediaquery) > 0) { while ($row = mysqli_fetch_row($mediaquery)) { ... stuff } }
3b. fetch 10, maintain pointer requested
<?php $lastpointer = “select pointer pointer_tracking”; $lastpointerresult = mysqli_query($con, $lastpointer); $lastpointer = mysqli_fetch_row($lastpointerresult) $lastpointer = $lastpointer[0]; $currentmediaquery = “select * media_ids id > {$lastpointer} limit {$lastpointer}, {$lastpointer +10}”; $mediaquery = mysqli_query($con, $currentmediaquery); if (mysqli_num_rows($mediaquery) > 0) { while ($row = mysqli_fetch_row($mediaquery)) { stuff… } } if (($lastpointer + 10 > 40) { $lastpointer = 1; } else { $lastpointer += 10; } mysqli_query($con, “update pointer_tracking set pointer = {$lastpointer}”);
you'll need create table called pointer_tracker id , pointer column, both integer types
Comments
Post a Comment