Jump to content

Page hangs


EchoFool

Recommended Posts

Hey i have a script using COMET server push effect, but it causes my browser to hang and i cannot understand why.

 

Heres the script that deals with PHP:

 

<?php
session_name('Current_User');
session_set_cookie_params(0, '/', '.mydomain.com'); // i use a subdomain so this is needed
session_start();
include("connect.php");
function getNewMessagesSince($timestamp) {
$Get = mysql_query("SELECT Count(push) AS Total FROM messages WHERE LastUpdate='$timestamp'") or die(mysql_error());
$row = mysql_fetch_assoc($Get);
    if($row['Total'] != 1) { 
    $Get = mysql_query("UPDATE push SET LastUpdate='".time()."'") or die(mysql_error());
    $Get = mysql_query("SELECT Message FROM messages WHERE Deleted='0'
                        ORDER BY postedon DESC LIMIT 1") or die(mysql_error());
    $row = mysql_fetch_assoc($Get);
        return array(
            'lastupdate' =>  time(),
            'html' => $row['Message'].' <br/>'
        );
    }
    return false;
}
while(! ($row = getNewMessagesSince($_POST['lastupdate']))) {
    //every half a second
    usleep(50000);
}


echo json_encode($row);
?>

 

 

Any ideas on what i got wrong ?

Link to comment
https://forums.phpfreaks.com/topic/223383-page-hangs/
Share on other sites

It does change if a user posts a message.

 

Plus the point of COMET JS is to use server push so the script keeps running

 

http://www.zeitoun.net/articles/comet_and_php/start

 

find with ctrl+ f : "The Backend Script"

 

You will see they add an infinite loop on purpose cos its the only way to do Comet JS

Link to comment
https://forums.phpfreaks.com/topic/223383-page-hangs/#findComment-1154732
Share on other sites

Well a COMET server rebuild the page (unless I am mistaken)

the problem is apache is being sent nothing and waiting for output

 

try this

 

add to the start

ini_set("output_buffering","Off");
ini_set("zlib.output_compression","Off");

 

//Loop

while(! ($row = getNewMessagesSince($_POST['lastupdate']))) {
    //every half a second
    usleep(50000);
    echo ""; //Yes echo nothing.. 
    flush(); // and output
}

 

Sounds strange but may just keep apache alive and in turn keep the browser pinging

Link to comment
https://forums.phpfreaks.com/topic/223383-page-hangs/#findComment-1154743
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.