目前正在做一个社交网站 (Thinkphp+mysql), 我想当某些用户触发了一些条件的时候通知另外一些在线的用户,比如说:发私信、给对方送了一件小礼物
目前我想到唯一的方法是 :
把要发送的消息放进Redis,然后在Action这个基类做一个redis的查询,这样用户每进行一次操作都会去查这个Redis是否有内容。但是这样不太科学,属于是被动式查询。
请教一下各位都有什么好的方法,万分谢谢!
回复内容:
目前正在做一个社交网站 (Thinkphp+mysql), 我想当某些用户触发了一些条件的时候通知另外一些在线的用户,比如说:发私信、给对方送了一件小礼物
目前我想到唯一的方法是 :
把要发送的消息放进Redis,然后在Action这个基类做一个redis的查询,这样用户每进行一次操作都会去查这个Redis是否有内容。但是这样不太科学,属于是被动式查询。
请教一下各位都有什么好的方法,万分谢谢!
https://github.com/walkor/web-msg-sender
这个绝对是你想要的,websocket+workerman实现的
DEMO:
后台发送消息的页面 http://workerman.net:3333/
用户接收消息的页面 http://workerman.net/web-msg-sender.html
原理:用户打开页面后浏览器会自动向后端服务器发送一个websocket(浏览器支持HTML5或者Flash就可以)连接,后端hold住这些连接,当想推送消息给浏览器时,向这些websocket连接写数据即可。
优点:
- 非轮询,性能很高,普通的服务器即可维持上万的连接
- 实时性好
- 兼容各种浏览器包括ie6(客户端支持flash或者html5任意一个就行)
1.轮询或者长轮询(普遍采用这种方式。这个也就是你说的方式,利用ajax不停的去请求服务器,看有没有新消息)
2.webSocket(需要浏览器支持html5。这个可以实现服务器主动推送。)
3.flash(一般网页游戏中都是利用这种方式)
1 轮询
用ajax隔一秒钟向后台询问
2 长连接
发送ajax请求到后台,但是后台阻塞不返回,知道快要超时再返回,途中遇到新消息时间可立即返回
3 websocket
客户端和服务器端建立连接通道,服务器可以主动发消息给浏览器,HTML5支持的特性
我觉得只要用户量达到一定规模,小公司做产品的话这个就应该走三方推送(极光推送,百度云推送等)去做,即使付费
自己实现的话设备和运维成本高
SignalR
内容的字数过少, 请详细描述
自己实现太麻烦,建议你使用GoEasy.免费的网页推送服务。
自己不用写代码,支持所有语言,几分钟就可以实现一个推送功能,非常简单,速度快,还可靠。
http://goeasy.io

Effective methods to prevent session fixed attacks include: 1. Regenerate the session ID after the user logs in; 2. Use a secure session ID generation algorithm; 3. Implement the session timeout mechanism; 4. Encrypt session data using HTTPS. These measures can ensure that the application is indestructible when facing session fixed attacks.

Implementing session-free authentication can be achieved by using JSONWebTokens (JWT), a token-based authentication system where all necessary information is stored in the token without server-side session storage. 1) Use JWT to generate and verify tokens, 2) Ensure that HTTPS is used to prevent tokens from being intercepted, 3) Securely store tokens on the client side, 4) Verify tokens on the server side to prevent tampering, 5) Implement token revocation mechanisms, such as using short-term access tokens and long-term refresh tokens.

The security risks of PHP sessions mainly include session hijacking, session fixation, session prediction and session poisoning. 1. Session hijacking can be prevented by using HTTPS and protecting cookies. 2. Session fixation can be avoided by regenerating the session ID before the user logs in. 3. Session prediction needs to ensure the randomness and unpredictability of session IDs. 4. Session poisoning can be prevented by verifying and filtering session data.

To destroy a PHP session, you need to start the session first, then clear the data and destroy the session file. 1. Use session_start() to start the session. 2. Use session_unset() to clear the session data. 3. Finally, use session_destroy() to destroy the session file to ensure data security and resource release.

How to change the default session saving path of PHP? It can be achieved through the following steps: use session_save_path('/var/www/sessions');session_start(); in PHP scripts to set the session saving path. Set session.save_path="/var/www/sessions" in the php.ini file to change the session saving path globally. Use Memcached or Redis to store session data, such as ini_set('session.save_handler','memcached'); ini_set(

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.


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

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.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Zend Studio 13.0.1
Powerful PHP integrated development environment
