how close a connection from server side that created by ajax from client side

Posted by saeid on Stack Overflow See other posts from Stack Overflow or by saeid
Published on 2013-11-11T21:51:14Z Indexed on 2013/11/11 21:52 UTC
Read the original article Hit count: 156

Filed under:
|
|
|

I have this sample php code:

<?php
function response($a) {
    @ob_end_clean();

    header("Connection: close");

    ob_start();

    echo $a;

    $length = ob_get_length();
    header("Content-Length: $length");
    ob_end_flush();
    flush();
}

response("test1");

sleep(5);
echo "test2";
?>

now I make a connection to server from client by ajax.

now I want to server only send "test1" to me and then close the connection. but connection not closed and wait 5 seconds and send me "test1 test2" !!

this is response headers from server to me :

X-Powered-By: PHP/5.3.27
Connection: close
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Cache-Control: private, no-cache, no-store, ------revalidate, no-transform
Transfer-Encoding: chunked
Content-Type: text/html

in response headers I do not see Content-Length header. is problem for this ??

or if not what I must do now for solving problem ??

© Stack Overflow or respective owner

Related posts about php

Related posts about http-headers