parRambSarm
New Member
I'm looking to implement real time notification updates on my social networking website. I have done some research on comet and i'm really fascinated by it.I've written some PHP code for a comet server, but I have a problem with my code. The problem is that I can't find out a way of making a query to a database (e.g an insert query) whilst the comet script is running. An example of this is if a user posts a new comment, it will fail to add to the database because of my comet script.What can I do about this? I've spent hours searching the internet trying to fix this/find a similar working example with no avail.\[code\]<?php set_time_limit(0); include("models/config.php"); global $mysqli,$db_table_prefix; $last = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0; $results = null; $flag=true; $stmt = $mysqli->prepare("SELECT id,timestamp FROM uc_user_activity WHERE timestamp > ? ORDER BY timestamp DESC"); $stmt->bind_param("i", $last); $stmt->bind_result($id,$timestamp); while($flag){ $stmt -> execute(); while ($row = $stmt->fetch()){ $flag = false; $results[] = array( "id" => $id, "timestamp" => $timestamp ); } $stmt -> close(); usleep(100000); clearstatcache(); } echo json_encode($results); ?>\[/code\]Am I doing this properly? Are there any other alternatives out there that won't cause the same problem as I'm having? I'd really like to know how to implement this properly. It seems StackOverflow has this functionality and it works perfectly.I would REALLY appreciate some guidance. Thanks in advance!