Webbased chat in php without using database or file

前端 未结 14 1015
失恋的感觉
失恋的感觉 2021-02-02 14:49

I am trying to implement a realtime chat application using PHP . Is it possible to do it without using a persistent data storage like database or file . Basically what I need is

14条回答
  •  借酒劲吻你
    2021-02-02 15:22

    One solution to achieving this is by writing a PHP socket server.

    
    

    You would execute this by running it through command line and would always have to run for your PHP clients to connect to it. You could then write a PHP client that would connect to the socket.

    \n";
    } else {
        $out = "GET / HTTP/1.1\r\n";
        $out .= "Host: www.example.com\r\n";
        $out .= "Connection: Close\r\n\r\n";
        fwrite($fp, $out);
        while (!feof($fp)) {
            echo fgets($fp, 128);
        }
        fclose($fp);
    }
    ?>
    

    You would have to use some type of ajax to call with jQuery posting the message to this PHP client.

    http://devzone.zend.com/209/writing-socket-servers-in-php/ http://php.net/manual/en/function.fsockopen.php

提交回复
热议问题