PHP Chat Room _websocket Technical Combat

Source: Internet
Author: User
Tags socket

Recently in the study of chat room technology, because I am doing PHP, definitely want to start from PHP, even a chat room, download the address:

Http://pan.baidu.com/s/1dDWsbip

Password: I2QZ

is in practice, ready to do a PHP chat room system out, PHP things easier to understand, but I encountered a problem is how to send information to the background of the front file server, then the study found that the JS WebSocket technology, the following is commonly used JS WebSocket Common operations:

var socket = new WebSocket (' ws://localhost:8080 ');
Open socket
Socket.onopen = function (event) {
}
Send an initialization message
Socket.send (' I am the client and i\ ' M listening! ');
Listening for messages
Socket.onmessage = function (event) {
Console.log (' Client received a message ', event);
};
Listening for socket shutdown
Socket.onclose = function (event) {
Console.log (' Client notified socket has closed ', event);
};
Close socket ....
Socket.close ()
Socket.onerror = function (evt) {console.log ("websocketerror!");

Here to download the version is window version of the PHP chat room, we need to configure how cmd run PHP environment,
Very simple, there are many tutorials on the Internet, search can, I only said that I encountered a little doubt, is to follow the tutorial configuration after the environment variable path, according to the truth, should be able to run the PHP cmd, but is not, after a day, found incredibly can be used, and later to understand is, after the configuration, Need to restart the computer to be effective.

Previously also used Node.js developed a number of small functions, feel that the PHP technology and Node.js functions are similar, are not required to run the environment, itself is a way of running the environment, chat room technology, in fact, I think the biggest breakthrough is that the server can actively send information to users, To control the browser on the client side, I think it's very significant. So no longer use Ajax Non-stop access to the server to get the latest technology, greatly reduce the pressure on the server, but also improve the user experience, but found that the technology is not very good commonly used up, so later will send some of the relevant video tutorials out, children can learn from each other exchange.
After downloading to the source code directly double-click the directory below the Start_for_win.bat file can start the chat room service,
Then visit: http://127.0.0.1:55151/can enter the chat room
Of course, you can also use the following command to control the service:
Start
Start in debug mode
php/var/www/workerman/start.php start

Start in daemon mode

php/var/www/workerman/start.php start-d
Stop it
php/var/www/workerman/start.php stop
Reboot
php/var/www/workerman/start.php restart
Smooth reboot
php/var/www/workerman/start.php Reload
View status
php/var/www/workerman/start.php status


I just said that the important point, debug mode startup, will be when you close the cmd window when the chat room service is closed, and to start in a daemon way, even if the cmd window is closed, chat room service is still running

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.