Giter Club home page Giter Club logo

mysql_websocket_chat's Introduction

Code Triagers Badge ESLint StyleLint Phpcs

MYSQL WEBSOCKET CHAT

Welcome to this Hackaton project I created for user hrushi on phpclasses.org. The idea was to create a web socket chat application that could be logging to a database. So here is what you need to get this up and running. Please note the minimum required PHP version is 7.0- this is not because it wanted this but it is because of the dependencies this project has.

Step 1: install composer

First thing you is installing composer on to your system. You can get composer here. Don't worry it might seem intimidating but it is not.

Step 2: Install the project

Using composer

Installing the project using composer is hands down the easiest way to get started. This method will download the project from GitHub and automatically install its dependencies for you. Presuming you installed composer (step 1) execute the following commands on the command-line.

$ composer create-project johnnymast/mysql_websocket_chat chat
$ cd chat

In the above example I am using a mac so my prompt will display different then you if you are on windows.

Downloaded from phpclasses.org

If you download this package in a zip file from phpclasses.org you will have to extract the zip package to a location of your liking. Then change directory into that directory and execute the following command on your prompt.

$ composer install

In the above example I am using a mac so my prompt will display different then you if you are on windows.

Step 3: Configure the server

Websocket configuration

This project can be split into two different components. The WebSocket server is the server.php in the root directory. The second part is the frontend part located in public/index.php. For the WebSocket server, there are two configuration options that you can configure in includes/config.php.

WEBSOCKET_SERVER_IP

This flag allows you to configure the WebSocket server's IP-address. By default the value 127.0.0.1 has been set.

WEBSOCKET_SERVER_PORT

This will configure what port the WebSocket server will listen on. The default value has been set to 8080. You can change this value if it clashes with other services running on your machine.

Database configuration

This server can run either with or without a database. By default i have disabled the use of a database server (ENABLE_DATABASE) but you can enable it by switching the ENABLE_DATABASE to true in the includes/config.php file.

Flag Description
DATABASE_HOST The database username goes in here. By default this has been set to root.
DATABASE_PORT The database port goes in here. By default this has been set to 3306.
DATABASE_USERNAME The database username goes in here. By default this has been set to root.
DATABASE_PASSWORD Enter the password to access the database there. By default this has been set to root.
DATABASE_DB Enter the name of the database here. By default this has been set to socket_chat.
ENABLE_DATABASE This flag will turn using the database on or off by setting its value to true or false.

Please note if you enable the database make sure you update the credentials as well (see table above). Also, if you enable the database make sure you have imported database.sql into your database.

Step 4: Fire up the WebSocket server

Change direction into the chat directory and fire up the server.

$ cd chat
$ php ./server.php

When you see no output and the command seems to hang that's when you know its running.

Step 5: Point a web service to the public directory

In the chat directory, you will find index.php. This file will be the client for your chat application. Make sure you set any web service its document root to the public/ folder. Alternatively, if you don't have access to a webserver you can also try using PHP's build-in webserver.

$ cd public
$ php -S 127.0.0.1:8000

This will start an webserver on port 8000

Step 6: Chat away!

Now open up 2 chat tabs and point them to localhost (or maybe a virtual host you configured) and chat away with your self.

Functionality

Private chats

If you want to test private chats you can single click any user in the user list on the right of the screen. Then type your message in the message bar, this will send a private message only to that user.

Changes

If you wish to know what has changed in this version of Mysql WebSocket Chat you can always checkout the changelog here.

Author

This package is created and maintained by Johnny Mast. For feature requests or suggestions you could consider sending me an e-mail.

Enjoy

Oh and if you've come down this far, you might as well follow me on twitter.

License

MIT License

Copyright (c) 2021 Johnny Mast

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

mysql_websocket_chat's People

Contributors

dependabot[bot] avatar johnnymast avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mysql_websocket_chat's Issues

Error: Currenty there is no connection to the server. reconnecting in 10

As I'm using xampp server

config.php

`<?php
date_default_timezone_set('EUROPE/AMSTERDAM');

define ('DATABASE_HOST', 'localhost');
define ('DATABASE_USERNAME', 'root');
define ('DATABASE_PASSWORD', '');
define ('DATABASE_DB', 'socket_chat');
define ('ENABLE_DATABASE', true);

/**

  • The host can either be an IP or a hostname
  • on this machine. The port is just the port
  • plain and simple.
    */
    define('CHAT_SERVER_HOST', '127.0.0.1');
    define('CHAT_SERVER_PORT', '80');

`
I tried to run aa

http://localhost/chat/chat/index.php

Got the Error as

Error: Currenty there is no connection to the server.
reconnecting in 10

Error: Currenty there is no connection to the server.

Hello Developer,

Thank you so much for creating awesome script for chat using websocket. Unfortunately i'm getting one error Error: Currenty there is no connection to the server. . I can not understand how to resolve that. i did the same server settings as you mentioned.

Please note i'm using mysqli connection as my PHP Version 7.1.7 and

image

Please advise me where i'm going wrong..

Thanks !
Hardik

Add Docker support

Docker support so the devs only have to run

$ docker-compose up

e.g. "I would like to see private chat's being implemented."

Add support to this in the new milestone.

Channel feature

Hi,

Is it possible to create a channel for 3,4 user so they can talk to each other and also chat privately?

Currently, if I send a message it delivers to all user but I want a group chat for different users so each user have their group of 3,4 people and they can chat in that channel or privately.

Thanks

Make script urls relative to current index.php directory.

Referencing #28

Sample fix for index.php:

<script type="text/javascript" src="./js/dom.js"></script>
<script type="text/javascript" src="./js/websockets.js"></script>
<script type="text/javascript" src="./js/interface.js"></script>

or

<script type="text/javascript" src="js/dom.js"></script>
<script type="text/javascript" src="js/websockets.js"></script>
<script type="text/javascript" src="js/interface.js"></script>

1.3 SSL Error handshake error

Hi,

I am using your websocket script in one of my application, when doing this on http this works like charm

But when trying to do this on ssl, getting "handshake error"

Using Ubuntu 16.04 with apache 2.4.18

can you please suggest on how to enable the script to use with ssl

Thanks

Add php 7 dependentie.

What feature are you missing?

e.g. "I would like to see private chat's being implemented."

What solution would you like to see?

e.g. "Please implement private chat."

Socket Close Abnormally 1006

Hello,
I followed your deployment instruction on one web server, but I am getting this error

WebSocket connection to 'wss://myIP:8080/' failed:
We have received an error! Event {isTrusted: true, type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …}
Connection closed with event code 1006 => The connection was closed abnormally, e.g., without sending or receiving a Close control frame

Websocket configuration defines should be renamed because it's causing confusion.

CHAT_SERVER_HOST and CHAT_SERVER_PORT should be renamed to WEBSOCKET_SERVER_HOST and WEBSOCKET_SERVER_PORT. Users seem to think this is for the HTTP part of the chat.

Also the README..MD should document using "php -S 127.0.0.1:2000"/

This issue was created because of github user @fahid744 had some problems getting the project up and running.

define('CHAT_SERVER_HOST', '127.0.0.1');
define('CHAT_SERVER_PORT', '8080');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.