So I want to know if its possible to store into database whoever reads a post. I know it's easy but here is the real process. Every post has a time to read(i.e 4 mins to read...). whoever enters the post page, I check the database if the user has read that article already or not. if not, i want to take the user id and article id and add it to the table, but only after a cetain amount of time has passed based on the time to read of each post. For example if a post is 5 mins to read and the user hasnt read the post before, i want to add his info to the table after 5 mins. Is this possible? Here is what I tried:
So first of all i tried the sleep function but didnt work cause it would tdelay the page loading and didnt work. I dont know if it's right or not but i did something like this :
$seconds = $time *60000; // converts minute to miliseconds.
if($post_data){
$check = new post();
$result = $check->checkreader($userid,$articleid);
if($result){
//user has read the post
}else{
sleep($seconds);
$check->addreader($id, $articleid);
}
the addreader and checkreader are functions inside a class (post) which check and insert the data into the database. I also tried the Java script set timout method but still didnt work. Most of the time, the function worked but the delay didnt work.
$seconds = $time * 60000;// converts minute to miliseconds.
if($post_data){
$check = new post();
$result = $check->checkreader($userid,$articleid);
if($result){
//user has read the post
}else{
echo "<script>
setTimeout(function(){".
$check->addreader( $id, $articleid)
.";}, $seconds);
</script>";
}
I want to do this so it could be a real reading system. if a reader spends the specified amount of time on a post, he has read it or else not. This way users cant just open a post and spam read everything. is there a simpler way or at leasta possible way?