In seguito ad un precedente help lanciato sul forum, sono riuscito a realizzare, prendendo spunto da script trovati in rete, questo famigerato long polling. Ora mi trovo costretto ad abusare di questa tecnica. Posto lo script per rendere l'idea:

codice:
jQuery( function(){
    // Start Long-polling for messages
    function post_longpolling( timestamp, lastId ){
        var t;

        if( typeof lastId == 'undefined' ){
            lastId = 0;
        }
                
        jQuery.ajax({
            url: 'php/bacheca/stream_post.php',
            type: 'GET',
            data: 'timestamp=' + timestamp + '&lastId=' + lastId,
            dataType: 'json',
            success: function( payload ){
                clearInterval( t );
                if( payload.status == 'results' || payload.status == 'no-results' ){
                    t=setTimeout( function(){
                        post_longpolling( payload.timestamp, payload.lastId );
                    }, 1000 );
                    if( payload.status == 'results' ){
                        jQuery.each( payload.data, function(i,msg){
            var new_r = ('<li><div class="tl-icon"><i class="iconfa-pencil"></i></div><div class="tl-post">'
+'            <div class="tl-author">'
+'                  <div class="img-rounded" style="border:1px solid #ccc;width:110px;float:left;margin:5px;">'
+'                    <div style="border:2px solid white;height:110px;overflow:hidden;"> <img src="'+ msg.foto_profilo +'" style=" width:110px" /> </div>'
+'                    </div>'
+'              <h5><a href="profile.php?id='+ msg.id_user +'">'+ msg.nome +' '+ msg.cognome+'</a> <small>'+ msg.data +'</small></h5>'
+'          </div>'
+'            <div class="tl-body">'
+'              <p>'+ msg.post +'</p>'
+'              </div>'
+'            <div class="tl-action">'
+'              <a href=""><i class="iconfa-heart"></i> Mi piace</a>'
+'              <a href=""><i class="iconfa-comment"></i> Commenta</a>'
+'              <a href=""><i class="iconfa-share-alt"></i> Condividi</a>'
+'              </div>'
+'            <div class="tl-comments">'
+'              <ul>'
+'                    <div class="row" id="respond'+ msg.id_post +'">'
+'                    </div>'
+'                    <li class="divider"></li>'
+'                    <li class="c-input">'
+'                      <div class="c-thumb"><img src="<?php echo $_SESSION['foto_profilo'];?>" alt="<?php echo $_SESSION['username'];?>"/></div>'
+'                      <div class="c-text">'
+'                        <form id="form_inserisci_replay'+ msg.id_post +'" action="php/bacheca/new_replay.php" method="post" name="form_inserisci_replay'+ msg.id_post +'">'
+'                          <input type="text" id="'+ msg.id_post +'" name="fr_replay" class="form-control  n_r" placeholder="Scrivi un commento" form="form_inserisci_replay'+ msg.id_post +'" />'
+'                          <input type="hidden" name="MM_insert" value="form_inserisci_replay">'
+'                          <input type="hidden" name="id_post" value="'+ msg.id_post +'">'
+'                          </form>'
+'                        </div>'
+'                    </li>'
+'                </ul>'
+'              </div>'
+'            </div>'
+'          </li>');
            
            jQuery('#visualizza_nuovi_post').prepend(new_r);
                            
                        });
                    }
                } else if( payload.status == 'error' ){
                    alert('Sono confuso, cortesemente ricarica la pagina!');
                }
            },
            error: function(){
                clearInterval( t );
                t=setTimeout( function(){
                    post_longpolling( payload.timestamp, payload.lastId );
                }, 15000 );
            }
        });
    }
    post_longpolling( '<?php echo time(); ?>' );

});
In sostanza, con una richiesta GET di ajax, aspetto dei risultati dal server (stream_post.php) dove, a seconda della risposta che ricevo, innietto i nuovi risultati.

stream_post.php è così formata:

codice:
<?php 
require_once('global.php');
require_once('../functions.php');

$timestamp = (int) trim( $_GET['timestamp'] );
$lastId = isset( $_GET['lastId'] ) && !empty( $_GET['lastId'] ) ? $_GET['lastId'] : 0;

if( empty( $timestamp ) ){
    die( json_encode( array( 'status' => 'error' ) ) );
}

$time_wasted = 0;
$lastIdQuery = '';
if( !empty( $lastId ) ){
    $lastIdQuery = ' AND id_post > ' . $lastId;
}

$new_messages_check = mysql_query("SELECT * FROM tbl_post JOIN members on tbl_post.id_user = members.id WHERE data_mess >= {$timestamp}" . $lastIdQuery ." ORDER BY id_post DESC");
$num_rows = mysql_num_rows( $new_messages_check );
if( $num_rows <= 0 ){
    while( $num_rows <= 0 ){
        if( $num_rows <= 0 ){
            
            // 40 Seconds are enough to forbid the request and send another one
            if( $time_wasted >= 60 ){
                die( json_encode( array( 'status' => 'no-results', 'lastId' => 0, 'timestamp' => time() ) ) );
                exit;
            }
            
            sleep( 1 );
            $new_messages_check = mysql_query("SELECT * FROM tbl_post JOIN members on tbl_post.id_user = members.id WHERE data_mess >= {$timestamp}" . $lastIdQuery . " ORDER BY id_post DESC");
            $num_rows = mysql_num_rows( $new_messages_check );
            $time_wasted += 1;
        }
    }
}

$new_messages = array();
if( $num_rows >= 1):
while ( $row = mysql_fetch_array( $new_messages_check, MYSQL_ASSOC ) ):
    $new_messages[] = array( 
     'id_post'             => $row['id_post'],
     'id_user'             => $row['id'],
     'data'             => quantotempo(strtotime($row['data'])),
     'nome'             => $row['nome'],
     'cognome'             => $row['cognome'],
     'foto_profilo'     => $row['foto_profilo'],
     'post'             => $row['post']
    );
endwhile;
endif;
$last_msg = end( $new_messages );
$last_id = $last_msg['id_post'];

die( json_encode( array( 'status' => 'results', 'timestamp' => time(), 'lastId' => $last_id, 'data' => $new_messages ) ) );
Tutto funziona alla perfezione.
Seguendo lo stesso e identico principio ho ottenuto le risposte in bacheca. Ma sono andato oltre. Apportando delle lievi modifiche sono riuscito ad avere gli utenti on line ed una vera e propria chat in perfetto stile facebook ma, haimè, quì le cose si son complicate.
La paggina diventa lentissima. Mi cause attese lunghissime anche nel fare il logout. Aprendo la console mi sono reso conto che dal client ci sono, e questo è solo il principio, ben 4 richieste pendenti in attesa di risposte dal server. Quì chiedo la vostra consulenza.
Potrebbe essere una soluzione quella di inviare un'unica richiesta e, a seconda della risposta del server, andare a modificare il DOM?
In sostanza mi chiedo se il problema lo posso aggirare riducendo il numero di richieste lato client o se devo fare i conti con il numero di connessioni aperte lato server?
Eventualmente io avrei pensato di lanciare una richiesta ajax su una pagina php, la quale lancia una serie di query e, lì dove ci dovessero essere novità, invia i risultati, esce dal ciclo, e ricomincia tutto. Vista la complessità della cosa spero sappiate consigliarmi se mi accingo a fare un lavoro inutile e ricercare altrove la soluzione. Restando in attesa, vi auguro tante belle cose