js+php realize real-time web chat function __js

Source: Internet
Author: User
Tags cdata live chat hasownproperty
<! DOCTYPE html> <!--[if Lt IE 7]>  



<?php//Display all Errors error_reporting (-1);

Ini_set (' display_errors ', ' on ');
Disable caching of the current Document:header (' Cache-control:no-cache, No-store, max-age=0, Must-revalidate '); Header (' Expires:mon, June 1997 05:00:00 GMT ');

Date in the past header (' Pragma:no-cache '); $filename = DirName (__file__).

'/data.txt '; Store new message in the file $message = isset ($_post[' message '))?
$_post[' message ']: ';
	if ($message!= ') {file_put_contents ($filename, $message);
Exit (); }//infinite loop until the data file is modified $LASTMODIF = isset ($_post[' timestamp '])?
$_post[' timestamp ': 0;
$currentmodif = Filemtime ($filename); while ($currentmodif <= $lastmodif) {//check if the data file has been modified Usleep (10000);//Sleep 10ms to UNL
	Oad the CPU clearstatcache ();
$currentmodif = Filemtime ($filename);
//Return a JSON array $response = array ();
$response [' message '] = file_get_contents ($filename); $response [' timestamp '] = $currentmodIf
echo Json_encode ($response); Flush ();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.