mysql_websocket_chat 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
mysql_websocket_chat 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
mysql_websocket_chat 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT License
开发语言 PHP
操作系统 跨平台
软件类型 开源软件
开源组织
地区 不详
投 递 者 首席测试
适用人群 未知
收录时间 2021-12-02

软件简介

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.

展开阅读全文

代码

评论 (0)

加载中
更多评论
暂无内容
发表了博客
2019/09/09 16:24

【WebSocket】WebSocket快速入门

WebSocket介绍   WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议。   WebSocket 使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动向客户端推送数据。在 WebSocket API 中,浏览器和服务器只需要完成一次握手,两者之间就直接可以创建持久性的连接,并进行双向数据传输。   在 WebSocket API 中,浏览器和服务器只需要做一个握手的动作,然后,浏览器和服务器之间就形成了一条快速...

0
7
发表了博客
2019/04/15 22:49

websocket --- 05 . http与websocket

一.http协议 1.基于 TCP 协议 2.一次请求 一次响应 断开 3.客户端永远处于主动状态 4.服务器永远处于被动状态  5.Http无状态 - 在服务器不保存客户端的信息 6.服务器无法主动找到客户端 二.轮询,长轮询,长连接   1.轮询 客户端向服务器不断发起类似Http请求 服务器不断的响应客户端 举例: 带上你的身份牌 - 服务器校验身份 大爷去找你的消息 - 服务器获取你应该拿到数据 if:拿到数据 e...

0
1
发表了博客
2018/03/20 16:53

WebSocket

Websocket是一个持久化的协议,相对于HTTP这种非持久的协议来说。 简单的举个例子吧,用目前应用比较广泛的PHP生命周期来解释。 HTTP的生命周期通过 Request 来界定,也就是一个 Request 一个 Response,那么在 HTTP1.0 中,这次HTTP请求就结束了。 在HTTP1.1中进行了改进,使得有一个keep-alive,也就是说,在一个HTTP连接中,可以发送多个Request,接收多个Response。但是请记住 Request = Response , 在HTTP中永远是这样,也...

0
0
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
暂无内容
0 评论
0 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部