Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pratt7384/Real-Time-Notification-Using-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

Real Time Notification Using PHP

Real Time Notification on client side using PHP and Socket

How To Use

Use backend.php on server side and do changes on this section

<?php
 while(1) {
	$html="Hello this is real time On Server :: ".date('Y-m-d h:i:s A T'); 
 echo '<script type="text/javascript">';
 echo 'comet.printServerTime("<center><b>'.$html.'</b></center>");';
 echo '</script>';
 flush(); // used to send the echoed data to the client
 usleep(10000);
 
 }
 ?>

You can query with database also and send to your client in place of $html

For the client side, you can do the changes on these section

printServerTime: function (time) {
	 var oldText;
	 if(oldText!=time){
		$('content_div').innerHTML="<div class='success'>"+time+"</div>";
	 }var oldText=time;
 },
 

Example

Lets suppose you want to show the latest comment from the database to your client then you can do it this way.

 $con=mysql_connect(DATABASE_HOST,DATABASE_USER,DATABASE_PASSWORD);
 $link=mysql_select_db(DATABASE_NAME);
 while(1) {
	$sql=mysql_query("select id,comment from postcomments order by id DESC");
	$lastComment=mysql_fetch_assoc($sql);
 	//$html="Hello this is real time".date('Y-m-d h:i:s'); 
 echo '<script type="text/javascript">';
 echo 'comet.printServerTime("<center><b>'.$lastComment['comment'].'</b></center>");';
 echo '</script>';
 flush(); // used to send the echoed data to the client
 usleep(10000);
 }

About

Real Time Notification on client side using PHP and Socket

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

AltStyle によって変換されたページ (->オリジナル) /