diff options
author | Julien Sere <jsere> | 2011-01-22 13:53:33 +0000 |
---|---|---|
committer | Julien Sere <jsere> | 2011-01-22 13:53:33 +0000 |
commit | 738943804f2e4005e1948ed19e0d02e4cd1df431 (patch) | |
tree | 19a9b074ebe4dfd32e4f9a5d81b45c70845b016f /app/v1_php/api/question | |
parent | 12f6cc3a6f90a67c1d922dd3d46a368b1066dee1 (diff) | |
download | 2011-usi-738943804f2e4005e1948ed19e0d02e4cd1df431.tar.gz 2011-usi-738943804f2e4005e1948ed19e0d02e4cd1df431.tar.bz2 2011-usi-738943804f2e4005e1948ed19e0d02e4cd1df431.zip |
On est bloqué à cause du long-polling... Pas de syncrho en php sous Windows
git-svn-id: file:///var/svn/2011-usi/trunk@9 db941bf7-0cb3-4dda-9634-87faf64f93a7
Diffstat (limited to 'app/v1_php/api/question')
-rw-r--r-- | app/v1_php/api/question/.htaccess | 3 | ||||
-rw-r--r-- | app/v1_php/api/question/index.php | 77 |
2 files changed, 80 insertions, 0 deletions
diff --git a/app/v1_php/api/question/.htaccess b/app/v1_php/api/question/.htaccess new file mode 100644 index 0000000..caad873 --- /dev/null +++ b/app/v1_php/api/question/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On +RewriteRule ^([0-9]*)$ index.php?n=$1 + diff --git a/app/v1_php/api/question/index.php b/app/v1_php/api/question/index.php new file mode 100644 index 0000000..fd8985e --- /dev/null +++ b/app/v1_php/api/question/index.php @@ -0,0 +1,77 @@ +<?php + +phpinfo(); + +set_time_limit(0); +//header('Content-type: text/plain'); +//require_once("../mysql_connect.inc.php"); + +//var_dump($_REQUEST); + + +/* +$mail=mysql_real_escape_string($_POST['mail']); +$password=mysql_real_escape_string($_POST['password']); + +$req="SELECT 1 FROM User WHERE mail='$mail' AND password='$password' LIMIT 1"; +$res=mysql_query($req); + +if ( mysql_num_rows($res) !== 1 ) { + header("erreur", true, 400); + exit(); +} + +header("OK : CREATED", true, 201); +setcookie("session_key", rand(0, 1024*1024*1024*2-1)); //TODO unicité +*/ + + + + +echo "Attente des autres joueurs\n"; + +// Long pooling +$shm = shm_attach( "42", 4, 0666 ); + +if ( !$sem || !$shm ) { + header("Problème semaphore/shared memory", true, 400); +} + +//TODO : debut section critique +if ( ! shm_has_var($shm, 'nbj') ) { + shm_put_var($shm, 'nbj', 1); +} else { + shm_get_var($shm, 'nbj'); + $nbj++; + $res=shm_put_var($shm, 'nbj', $nbj); + if ( $res!==true ) { + header("Problème shm_put_var", true, 400); + exit(); + } +} +echo "Il y a $nbj joueurs\n"; +//TODO : Fin section critique + +$go=false; +while (!$go) { + shm_get_var($shm, 'nbj'); + if ( $nbj === 2) { + $go=true; + } + sleep(1); +} + + +//TODO Récupérer la question en base ? +echo ' +{ +"question" : "question ' . $_GET['n'] . '", +"answer_1" : "string", +"answer_2" : "string", +"answer_3" : "string", +"answer_4" : "string", +"score" : number +} +'; + +?> |