How does the Facebook ticker work?

Most Facebook is written in PHP, but there are several front-end functions that other scripting languages ​​use.

Ticker (a small box in the upper right corner of the news page that displays the latest posts, etc.):

I assume AJAX is involved in this, but I was wondering how it all works. I developed something similar (but more basic) in flash memory where flash checks every millisecond (as well as in real time) for updates, but Facebook clearly does not use flash for this.

I know that data can be transferred back and forth using AJAX, but how can they do it instantly? Are you constantly checking?

Just wondering

+6
source share
3 answers

They use a long survey

  • The request is sent to the server
  • The request does not close the connection until the news
  • When there is news, the script closes the connection, and the news is visible

A lengthy poll of a PHP script might look like

$seconds = 1; while($seconds < 60) { // browser can enforce one minute timeout $updates = get_updates(); //check for updates if ($updates) { echo $updates; // json encoded string die(); } $seconds++; sleep(1); } 
+10
source

This is most likely done with a survey (i.e. a constant check, as you call it), although 1 millisecond is too frequent. I guess something more in seconds.

They probably remember the last item in your feed now and every n seconds they retrieve the items you entered after that and refresh the page accordingly.

+1
source

There is a connection pool in php with a relay.

You can use the following link for reference.

http://gonzalo123.wordpress.com/2010/11/01/database-connection-pooling-with-php-and-gearman/

0
source

Source: https://habr.com/ru/post/901611/


All Articles