summaryrefslogtreecommitdiffstats
path: root/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'ajax')
-rw-r--r--ajax/chat.ajax.php40
1 files changed, 23 insertions, 17 deletions
diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php
index 02a11c6..8302c33 100644
--- a/ajax/chat.ajax.php
+++ b/ajax/chat.ajax.php
@@ -6,6 +6,12 @@ session_start();
// exit;
// }
+
+ini_set('display_errors',1);
+ini_set('display_startup_errors',1);
+error_reporting(-1);
+
+
if (isset($_SESSION['chatLastReset'])) $chatLastReset = $_SESSION['chatLastReset'];
else $chatLastReset = 0;
@@ -31,6 +37,8 @@ session_write_close();
$userID = $_SESSION['userID'];
$chatLockDown = false;
+$use_psuedo_longpoll = true;
+
// STOP CHAT?
//$chatLockDown = true;
@@ -42,6 +50,7 @@ $chatLockDown = false;
require_once('../includes/chats.php');
+
$sent = false;
if (isset($_REQUEST['messages'])) {
@@ -110,36 +119,33 @@ if (isset($_REQUEST['messages'])) {
if ($_REQUEST['getChatFromID']) {
$getChatID = $_REQUEST['getChatFromID'];
- if ($sent) {
- //Wait .2 seconds
- usleep(200000);
- //echo "yesSent";
+ if ($sent == true AND $use_psuedo_longpoll == true) {
+ // PSUEDO LONG POLLING: - This loops to try to retrieve
+ // the message you just sent, back from the server.
+
for( $i = 1; $i < 3; $i++) {
- //echo "loop";
$data = getChat($getChatID);
if ($data !== false) {
- //$data['debug'][] = "Count times: $i";
- //$data['debug'][] = "Count value:".count($data);
echo prepareChatData($data);
exit;
}
- //Wait .1 seconds
- usleep(100000);
+ //Wait .01 seconds per loop
+ usleep(10000);
}
}
$json = prepareChatData(getChat($getChatID));
echo $json;
}
-exit;
function prepareChatData($data) {
- if ($data) {
- foreach($data as &$user) {
- //$user['message'] = $user['message'].'write-append';
- $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now");
- }
- return json_encode($data);
+ if (!$data)
+ {
+ return false;
+ }
+ foreach($data as &$user) {
+ //$user['message'] = $user['message'].'write-append';
+ $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now");
}
- return $data;
+ return json_encode($data);
}
?> \ No newline at end of file