Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am new to the Long-polling requests concept and having an issue with the requests from an Angular project to PHP XAMPP local server. When the request time limit is set to 0 like

set_time_limit(0);

The requests stay alive forever. Even after the client reloads the website page or closes the whole tab the request won't stop processing the script and keep repeating it. If the client reloads the website page 10 times then closes the tab, the PHP server will keep processing 10 different requests for no one.

I am wondering how to avoid that or, how to exit the request once the client is not going to receive its response by reloading/leaving the page?

my api code:

            set_time_limit(0);
            $accountId = 1;
            $database = DBManager::link();

            while (true) {

                $database->call('account_get_notifications_updates')
                    ->value('_accountId', $accountId, DBParams::INT);

                if ($database->run()) {

                    $sqlResults  = $database->fetchArray();
                    $returnValue = $database->getReturnValue();
                    
                    if ($returnValue == 0) {
                        // add the new notifications to the response and exit
                        $this->Response->SetData($sqlResults['dataSet2']);
                        break;
                    } else {
                        sleep(30);
                        continue;
                    }
                }

                throw new Exception($database->getError()->message);
            }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...