My long polling isn't working:
server.php
<?php
require 'pdo.php';
set_time_limit(0);
while (true)
{
$requestedTimestamp = isset($_GET['timestamp']) ? (int)$_GET['timestamp'] : time();
clearstatcache();
$stmt = $pdo->prepare( "SELECT * FROM publication WHERE publication_time > :requestedTimestamp" );
$stmt->bindParam( ':requestedTimestamp', $requestedTimestamp );
$stmt->execute();
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
if (count($rows) > 0) {
$publication = $rows['publication'];
$timestamp = strtotime($rows['publication_time']);
$my = array('publication'=>$publication,'timestamp'=>$timestamp);
$myJSON = json_encode($my);
echo $myJSON;
break;
} else {
sleep(2);
continue;
}
}
?>
The problem is giving me a headache: Independent of $timestamp
, the result I got from the SELECT is the same, in case I, my last $timestamp = 1439056820 (08/08/2015 15:00:20);
publication_time = timestamp field;