PHP Classes
elePHPant
Icontem

Simple PHP Web Chat: Chat system with Websockets or AJAX as fallback

Recommend this page to a friend!

  Author Author  
Name: PLSCIS PLP <contact>
Classes: 3 packages by
Country: India India
Age: ???
All time rank: 86950 in India India
Week rank: 191 Up17 in India India Up
Innovation award
Innovation award
Nominee: 1x


  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This package implements a chat system with Websockets or AJAX as fallback.

It generates HTML with JavaScript to connect to a chat server using Websockets.

It falls back to AJAX long polling requests if Websockets are not supported by the user browser version.

It provides the following features:

- Registration, login and password recovery of the users
- Search, add and group user contacts
- Broadcast messages to groups of users
- Desktop notifications, sound alerts, automatic scroll to new messages
- Exchange files between users
- Multiple chat sessions in different tabs
- Keep the history of old chat messages
- File Attachments
- Desktop notifications, sound alert, auto scroll to message
- Audio and video chat using WebRTC

By default it works with files for storage so it does not require a database server.

Details
{startverticalbanner}
Its a simple web based chat system using HTML5 websockets / HTML5 SSE with ajax long polling as fall-back to provide a very fast and smooth experience (can work with or without any database server).

It can be used as standalone or as module / plugin in any website. Implemented in core php and js code using jquery. Very simple, feature rich and fully customizable chat system. Auto fall-back from html5 websockets to html5 sse to ajax long polling

Fetaures:
1) Registration, login, forgot password
2) Search and add contacts, manage groups
3) Broadcasting, one to one & group chat
4) Desktop notifications, sound alert, auto scroll to new message
5) File attachments
6) Multiple tabbed chat
7) History of old chat messages
& *Audio-Video chat using WebRTC integrated into code, but not yet tested

All these managed without use of any database server. Its fully standalone but can be easily integrated with any database server using simple cron. Code for db integration is not included in this package



Overview on structure of data files:

Chat messages are stored inside /tmp folder as temporary files. One message in one file.

Let say user1 is chating with user2,
	files for those messages will be inside /tmp/user1-user2/
	files for broadcasted messages will be inside /tmp/mt/
	folders starting with 'g:' are for groups and will contain files of group chat messages
	once a message file for e.g 'file123' is read by 'user1' to prevent re-reading one file named 'user1_file123' is created
	while reading message files for e.g 'file123', if file 'user1_file123' exists then 'file123' is skiped

If using db server, you need to create a cron which will read all these message files and store it with appropriate relation in db.
Also, if using db server for better performance you can remove or comment deleting and history code and manage it in cron.

History files are created concatinating two user's names or username with group (in case of history for a group)
So, for group each user have separate history files.
History files are stored inside /h for broad casted messages and inside /h/uh for inidividual and group chats

Other files and folders used:
/files/un	User's profile file containing data of contact names, group names, username, email, password, contact and group request, verification code
/files/grp	Contains a file for each group which contains contact's names and requested contacts
/files/ou	Contains a file for each online user and can be used for storing current logged-in session values
/files/um	Contains folder for each relation of user inside that user's folder 
			For e.g. 
				/files/um/user1 	Will contain a folder 'user1-user2' if user1 has a contact user2 and in case of group it will have folder with 'g:groupname-groupid'. 
									This is used to easily retrive chat data from same folder inside /tmp and avoid exessive relation mapping or reading from files.
									So, if user1 and user2 are contacts and are in a 'group1' they both will have once folder in /files/um and inside each folder they will have 'user1-user2' and 'g:group1-123' folders.
									Also, same 'user1-user2' and 'g:group1-123' folders are used in /tmp to store respective message files.

While fetching messages for user1, name of all folders inside /files/um/user1 are obtained and files inside same named folders from /tmp are read and send to user1. 

So at server side instead of R-DBMS server file system is constantly monitored for each user, for any new or unread files and as soon as any such file found contents of those files are read and send to the respective user & also that flag file is created so that same file is not fetched again.

Now we need a cron which will read all these message files and store it with appropriate relation in db and once data from a file is inserted delete that temporary message file.

To insert message data in to R-DBMS server we can use a cron at every 1 minute which will read all message files and create separate sql file per each cron and store that sql file in a secure folder and then delete those message files which are read. Now, those sql files can be dumped into mysql at every 30 minutes. The reason behind separating insertion into two crons is to reduce insert frequency into DB server and also at the same time maintain less files on file system to look into for new messages.

In this manner persistent storage of our data is done in R-DBMS server and whenever user needs to show history of chat data can be fetched from R-DBMS. Again, we can limit data in R-DBMS server to let say 3 months for each user after which a download facility can be given for user to get their old data in a file which once downloaded will be deleted after certain period of time and as those data are already deleted from DB server, won't appear in chat history in application.

Thus, excessive sql quering, relation mapping and file reading is avioded. Also creation of huge file is avoided here by creating separate files for each messages and handling as much as possible checks and relations using directory exists and file exists method.

If want to use Websockets, to start web-server for websocket requests, execute  below command in command line:
/usr/bin/php -q /var/www/simple-web-chat/chat.php

sc.php is the entry script so main url of application will be like: http:// ... /simple-web-chat/sc.php 

Also, make sure folders "files/", "tmp/", "h/" and "pub/" have read and write permissions for web-server user (generally that user is 'www-data' if using apache2 http server).

To, know more about theoretical (technical) concept in detail you can visit:
http://www.plsein.com/project/theory/filesystem_based_data_management_architecture

  Classes of PLSCIS PLP  >  Simple PHP Web Chat  >  Download Download .zip .tar.gz  >  Support forum Support forum (5)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: Simple PHP Web Chat
Base name: simple-web-chat
Description: Chat system with Websockets or AJAX as fallback
Version: 1.0.31
PHP version: 5.0
License: MIT/X Consortium License
All time users: 2049 users
All time rank: 1871
Week users: 5 users
Week rank: 184 Up
 
  Groups   Rate classes User ratings   Applications   Related pages   Files Files  

  Groups  
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Chat Chating and instant messaging View top rated classes
Group folder image AJAX Interact with the Web server without page reloading View top rated classes


  Recommendations  

What is the best PHP chat room class?
I need a simple chat package

Live video streaming using webrtc
One to many live video streaming for online education

What is the best PHP real time chat class?
Chat similar to Google hangouts

Websocket chat
Websocket chat with real time updates


  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Sufficient (75%) Sufficient (66%) Sufficient (66%) - - - Not sure (50%) 2095
Month: Not yet rated by the users

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.


  Related pages  
http://www.plsein.in/project/theory/filesystem_based_data_management_architecture
Theoretical (Technical) Concept
http://www.plsein.in/site/products/products#web-apps
Link to simple web chat's main webpage
simplewebchat
Direct download link available at sourceforge.net

  Files folder image Files  
File Role Description
Files folder imageclasses (17 files)
Files folder imagecss (1 file)
Files folder imagefiles (1 file, 4 directories)
Files folder imageh (1 file, 1 directory)
Files folder imageimages (1 file)
Files folder imagejs (6 files)
Files folder imagelib (2 files, 1 directory)
Files folder imagepub (2 files)
Files folder imagetmp (1 file, 2 directories)
Accessible without login Plain text file .htaccess Data htaccess
Accessible without login Plain text file acceptcreq.php Appl. normal request handler file for accept contact request
Accessible without login Plain text file acceptgreq.php Appl. normal request handler file for accept group request
Accessible without login Plain text file biCChat.php Appl. normal request handler file to init chat with contact
Accessible without login Plain text file biGChat.php Appl. normal request handler file to init chat with group
Accessible without login Plain text file chat.php Appl. script which starts websocket php server
Accessible without login Plain text file chkusr.php Appl. normal request handler file to check user's identity
Accessible without login Plain text file common.php Conf. common config file
Accessible without login Plain text file cp.php Appl. normal request handler file for change password
Accessible without login Plain text file csrch.php Appl. normal request handler file for contact search
Accessible without login Plain text file filehandler.php Appl. normal request handler file for file uploads
Accessible without login Plain text file history.php Appl. normal request handler file to display user's history
Accessible without login Plain text file managegroup.php Appl. normal request handler file for managing groups
Accessible without login Plain text file nchat.php Appl. normal request handler file for fetching new chat messages
Accessible without login Plain text file newcontact.php Appl. normal request handler file for adding new contact
Accessible without login Plain text file ReadMe.txt Doc. Read Me file
Accessible without login Plain text file rejectcreq.php Appl. normal request handler file to reject contact request
Accessible without login Plain text file rejectgreq.php Appl. normal request handler file to reject group request
Accessible without login Plain text file rejectgroup.php Appl. normal request handler file for removing a group from contact list
Accessible without login Plain text file removecon.php Appl. normal request handler file to remove a contact from contact list
Accessible without login Plain text file reply.php Appl. normal request handler file to send a message
Accessible without login Plain text file sc.php Appl. entry script
Accessible without login Plain text file selcgroup.php Appl. normal request handler file to get group contacts
Accessible without login Plain text file ssrch.php Appl. normal request handler file to search people for adding as contact
Accessible without login Plain text file uverify.php Appl. normal request handler file for user verification

  Files folder image Files  /  classes  
File Role Description
  Plain text file class.AcceptRequest.php Class Accept Contact and Group Request
  Plain text file class.CheckUserIdentity.php Class Check User's Identity
  Plain text file class.GroupDetails.php Class To get details of a group
  Plain text file class.History.php Class Provide history file to user
  Plain text file class.InitContactChat.php Class Init chat with contact
  Plain text file class.InitGroupChat.php Class Init chat with group
  Plain text file class.Mail.php Class Class to Send Mail
  Plain text file class.ManageGroups.php Class Manage User's Groups
  Plain text file class.Messages.php Class Read User Messages
  Plain text file class.ModifyPass.php Class Change Password
  Plain text file class.NewContact.php Class Add New Contact
  Plain text file class.RejectRequest.php Class Reject Contact or Group Requests
  Plain text file class.RemoveContacts.php Class Remove from contact list
  Plain text file class.Reply.php Class Reply or Send Message
  Plain text file class.SearchPeople.php Class Search People
  Plain text file class.UserContacts.php Class To get user's contacts
  Plain text file class.UserVerification.php Class Verification of user

  Files folder image Files  /  css  
File Role Description
  Accessible without login Plain text file style.css Data css file

  Files folder image Files  /  files  
File Role Description
Files folder imagegrp (2 files)
Files folder imageou (1 file)
Files folder imageum (1 file, 1 directory)
Files folder imageun (4 files)
  Accessible without login Plain text file .htaccess Data htaccess

  Files folder image Files  /  files  /  grp  
File Role Description
  Accessible without login Plain text file g1-52a46a6d270de.u Output sample group file
  Accessible without login Plain text file sample.txt Doc. description

  Files folder image Files  /  files  /  ou  
File Role Description
  Accessible without login Plain text file sample.txt Data online users

  Files folder image Files  /  files  /  um  
File Role Description
Files folder imagedev (1 file, 1 directory)
  Accessible without login Plain text file sample.txt Data relation for user messages

  Files folder image Files  /  files  /  um  /  dev  
File Role Description
Files folder imagedev-t (1 file)
  Accessible without login Plain text file sample.txt Doc. description

  Files folder image Files  /  files  /  um  /  dev  /  dev-t  
File Role Description
  Accessible without login Plain text file sample.txt Doc. description

  Files folder image Files  /  files  /  un  
File Role Description
  Accessible without login Plain text file dev.u Output sample profile file
  Accessible without login Plain text file sample.txt Data description
  Accessible without login Plain text file t1.u Output sample profile file
  Accessible without login Plain text file t2.u Output sample profile file

  Files folder image Files  /  h  
File Role Description
Files folder imageuh (1 file)
  Accessible without login Plain text file .htaccess Data history files

  Files folder image Files  /  h  /  uh  
File Role Description
  Accessible without login Plain text file sample.txt Data history files

  Files folder image Files  /  images  
File Role Description
  Accessible without login Image file chat-icon.png Icon icon image

  Files folder image Files  /  js  
File Role Description
  Accessible without login Plain text file chat.js Data chat js
  Accessible without login Plain text file jquery.form.js Data Jquery form plugin
  Accessible without login Plain text file jquery.js Data Jquery main js
  Accessible without login Plain text file messagechat.js Data chat base js
  Accessible without login Plain text file simplewebrtc.js Data WebRTC js for audio video chat
  Accessible without login Plain text file socket.io.js Data socket.io.js used for WebRTC

  Files folder image Files  /  lib  
File Role Description
Files folder imagephpmailer (1 file)
  Plain text file Client.class.php Class websocket client class
  Plain text file Server.class.php Class websocket server class

  Files folder image Files  /  lib  /  phpmailer  
File Role Description
  Accessible without login Plain text file sample.txt Data phpmailer here

  Files folder image Files  /  pub  
File Role Description
  Accessible without login Plain text file .htaccess Data htaccess
  Accessible without login Plain text file sample.txt Data user uploaded files

  Files folder image Files  /  tmp  
File Role Description
Files folder imagemt (1 file)
Files folder imageum (1 file)
  Accessible without login Plain text file .htaccess Data htaccess

  Files folder image Files  /  tmp  /  mt  
File Role Description
  Accessible without login Plain text file sample.txt Data temporary broadcasted messages here

  Files folder image Files  /  tmp  /  um  
File Role Description
  Accessible without login Plain text file sample.txt Data temporary user chat messages here

Install with Composer Install with Composer - Download Download all files: simple-web-chat.tar.gz simple-web-chat.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.