Instant content updates based on server push, Login/logout/status change/messages, etc.
The latest version can be natively supported IE series browser, based on the HTTP long connection
InstallationSwoole extension
PECL Install Swoole
Swoole Frame
Composer Install
RunConfigure the client directory to the Nginx/apache virtual host directory to make the client/index.html accessible. Modify the Client/config.js, IP and port for the corresponding configuration.
PHP webim_server.php
Detailed Deployment Instructions1. Install composer (PHP dependency package tool)
| PHP mv Composer.phar/usr/local/bin/composer
Note: If the PHP interpreter program is not set to the environment variable path, it needs to be set. Because composer file first behavior #!/usr/bin/env PHP, and cannot be modified. More detailed description of the composer: http://blog.csdn.net/zzulp/article/details/18981029
2.composer Install
Switch to Phpwebim project directory, execute instruction composer install, if slow
Composer Install--prefer-dist
3.ningx/apache configuration (This does not use the Web AppServer provided by Swoole_framework)
Nginx
server { listen ; server_name im.swoole.com; Index index.shtml index.html index.htm index.php; Root /path/to/phpwebim/client; Location ~. *\. (PHP|PHP5) $ { fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Include fastcgi.conf; } Access_log /library/webserver/nginx/logs/im.swoole.com access;}
Apache
<virtualhost *:80> documentroot "path/to/phpwebim/client" ServerName im.swoole.com AddType application/x-httpd-php. php <directory/> Options Indexes followsymlinks allowoverride None Require all granted directoryindex index.php </Directory> </VirtualHost>
4. Modify the configuration phpwebim/config.php
$config [' server '] = Array ( //Listen for host ' host ' = ' 0.0.0.0 ', //Listen for Ports ' port ' = ' 9503 ', // WebSocket URL address for use by the browser ' url ' = ' ws://127.0.0.1:9503 ',);
- Server.host Server.port is the IP and port of the Webim server, which is the WebSocket server, and the other selections are modified according to the specific circumstances
- The server.url corresponds to the server IP or domain name and the port of the WebSocket service, which is the WebSocket address provided to the browser.
- Webim.data_dir to modify the directory where the chat record is stored, you must have writable permissions
5. Start the WebSocket server
PHP phpwebim/webim_server.php
IE does not support websocket and requires flashwebsocket emulation, modify the corresponding port in flash_policy.php, and then start flash_policy.php.
PHP phpwebim/flash_policy.php
6. Bind the host and access the Chat window (optional)
If the URL uses ip:port directly, there is no need to set it.
Vi/etc/hosts
Increase
127.0.0.1 im.swoole.com
Open in Browser: http://im.swoole.com
Quick understanding of Project architecture1. Directory structure
+ Phpwebim |-webim_server.php//websocket Protocol Server|-config.php//swoole Run Configuration|+ Swoole.ini//WebSocket protocol implementation Configuration|+ Client |+Static|-Config.js//WebSocket Client Configuration|-index.html//Login Interface|-main.html//chat room main interface|+ data//Run data|+Log //Swoole Logs and Webim logs|+ SRC//Webim class file storage directory|+ Store |-file.php//Default memory Tmpfs file System (LINUX/DEV/SHM) to store the data, if not Linux, manually modify the $shm_dir|-redis.php//Store chat data in Redis|-server.php//Inherit the class that implements WebSocket, complete certain business functions|+ Vendor//Dependency Package directory
2.Socket Server and Socket client communication data format
such as: Login
Client sends data
{ "cmd" : "login" , "name" : "xdy" , "avatar" : "http://tp3.sinaimg.cn/1586005914/50/5649388281/1" }
Server Response Login
{ "cmd" : "login" , "fd" : "to" , "name" : "xdy" , "avatar" : "http://tp3.sinaimg.cn/1586005914/50/5649388281/1" }
You can see the Cmd property, which is specified by the client and the server when it is sent, primarily for the client or server callback handler function.
3. The relationship between several agreements or services that need to be cleared
HTTP protocol: Hypertext Transfer Protocol. Simplex communication, waiting for the client to respond after the request.
WebSocket protocol: HTML5 is a new protocol that implements full-duplex communication between the browser and the server. Both the server port and the client can pull data.
Web server: You can use Swoole-based app server as a Web server in this project, or you can use traditional Nginx/apache as a Web server
Socket server: This project is a server in which the browser's WebSocket client is connected, and Swoole_framework has a PHP version that implements the WebSocket protocol.
WebSocket Client: Browsers that implement HTML5 support WebSocket objects, such as implementations that provide a flash version in this project are not supported.