Skip to content

Instantly share code, notes, and snippets.

@julesbou
Created September 11, 2011 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesbou/1210174 to your computer and use it in GitHub Desktop.
Save julesbou/1210174 to your computer and use it in GitHub Desktop.
Is it a good idea ? (not tested)
<?php
// Alternative to the long polling system used in lichess (github.com/ornicar/lichess)
// - We could use an ajax request on a php script with an infinite loop until version has changed.
$userVersion = $_GET['version']
$version = $db->stack->find($_GET['player_id'])->getVersion();
while ($userVersion <= $version) {
usleep(10000);
$version = $db->stack->find($_GET['player_id'])->getVersion();
if ($version !== $userVersion) {
return json_encode(array(
'events' => $stack->getEventsSince($userVersion))),
'version' => $version,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment