一个基于WebSocket的WEB消息推送框架
web-msg-sender是一款web长连接推送框架,采用PHPSocket.IO开发,基于WebSocket长连接通讯,如果浏览器不支持WebSocket则自动转用comet推送。 通过后台推送消息,消息可以即时推送到客户端,非轮询,实时性非常好,性能很高。
特点:
多浏览器支持
支持针对单个用户推送消息
支持向所有用户推送消息
长连接推送(websocket或者comet),消息即时到达
支持在线用户数实时统计展示
支持在线页面数实时统计展示
支持跨域推送
下载
https://github.com/walkor/web-msg-sender
WEB消息推送框架
接收消息页面:http://www.workerman.net:2123/
推送接口url:http://www.workerman.net:2121/?type=publish&to=uid&content=content
其中to为接收消息的uid,如果传空则向所有人推送消息 content 为消息内容
Linux环境安装启动
1、下载web-msg-sender,并解压缩到任意目录
2、启动workermanphp start.php start -d如下图
3、浏览器访问端口http://ip:2123或者http://域名:2123,例如 http://workerman.net:2123如图:(如果无法访问请检查服务器防火墙)
前端测试:
支持跨域推送,开发者可以不用建立服务端,直接使用线上的推送服务测试,只要引入js文件并设置下端口及回调即可,例如在任意站点中加入如下代码即可收到消息并统计数据:
<script src='http://cdn.bootcss.com/socket.io/1.3.7/socket.io.js'></script> <script> // 连接服务端 var socket = io('http://workerman.net:2120'); // uid可以是自己网站的用户id,以便针对uid推送以及统计在线人数 uid = 123; // socket连接后以uid登录 socket.on('connect', function(){ socket.emit('login', uid); }); // 后端推送来消息时 socket.on('new_msg', function(msg){ console.log("收到消息:"+msg); }); // 后端推送来在线数据时 socket.on('update_online_count', function(online_stat){ console.log(online_stat); }); </script>
后端调用api向任意用户推送:
<?php // 指明给谁推送,为空表示向所有在线用户推送 $to_uid = ""; // 推送的url地址,上线时改成自己的服务器地址 $push_api_url = "http://workerman.net:2121/"; $post_data = array( "type" => "publish", "content" => "这个是推送的测试数据", "to" => $to_uid, ); $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $push_api_url ); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_HEADER, 0 ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data ); $return = curl_exec ( $ch ); curl_close ( $ch ); var_export($return);
相关文章:

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

The article discusses various methods for page redirection in PHP, focusing on the header() function and addressing common issues like "headers already sent" errors.

Article discusses type hinting in PHP, a feature for specifying expected data types in functions. Main issue is improving code quality and readability through type enforcement.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
