


javascript - I want to create a web chat function similar to QQ, how to implement it? ?
When making a web-based chat tool, what method do you usually use for real-time messaging? ?
What I know:
ajax polling (they say it’s a waste of resources, not good...)
EventSource (poor support, IE doesn’t support it at all..)
WebSoket (don’t know much about it...)
Moreover, after searching on Baidu, I learned that when the browser does not support WebSocket, there are actually third-party libraries that can implement WebSocket. Is the so-called WebSocket the same as EventSource? The core principle is to use ajax polling to achieve instant communication. ? ?
What is the currently commonly used web real-time communication technology? ? Xiaobai asks for advice, asks the great god to come by air...
Reply content:
When making a web-based chat tool, what method do you usually use for real-time messaging? ?
What I know:
ajax polling (they say it’s a waste of resources, not good...)
EventSource (poor support, IE doesn’t support it at all..)
WebSoket (don’t know much about it...)
Moreover, after searching on Baidu, I learned that when the browser does not support WebSocket, there are actually third-party libraries that can implement WebSocket. Is the so-called WebSocket the same as EventSource? The core principle is to use ajax polling to achieve instant communication. ? ?
What is the currently commonly used web real-time communication technology? ? Xiaobai asks for advice, asks the great god to come by air...
Workerman is an open source high-performance PHP socket
server framework developed purely in PHP
. It is widely used in the development of mobile apps, mobile game servers, online game servers, chat room servers, hardware communication servers, smart homes, Internet of Vehicles, Internet of Things and other fields. Supports TCP long connections, supports Websocket, HTTP and other protocols, and supports custom protocols. Based on Workerman, developers can focus more on business logic development and no longer have to worry about the underlying development of PHP Socket.
git repository: https://github.com/walkor/Wor...
Chinese homepage: http://www.workerman.net/
Chinese documentation: http://doc3.workerman.net/
The questioner can try this.
Talking about two PHP solutions, one of them, WorkerMan, has been mentioned by someone, and the other is PHPWebIM developed by Fengge based on Swoole.
PECL extension Swoole supports using PHP to write high-performance socket applications:
<code>apt-get install php-pear php5-dev yum install php-pear php-devel pecl remote-info swoole pecl install swoole</code>
PHPWebIM is an official WebSocket web instant chat tool developed by Swoole based on PHP Swoole extension and Swoole Framework.
PHPWebIM supports WebSocket+Comet protocols and can be used in all types of browsers including IE, please see Demo.
If you only want to implement relatively real-time message notifications, you can also use AJAX polling:
1) Single page (only poll on one page)
2) SetInterval interval passive polling (keep-alive persistent connection, such as 30 seconds)
3) window.onfocus window gets focus and is actively triggered (event-driven)
The polling interval is too short and users open too many pages, which may cause excessive pressure on the server.
For businesses that do not have high real-time requirements, you can Increase the interval, such as polling once every 2 minutes.
<code>window.onblur = function() {document.title = '失去焦点';}; window.onfocus = function() {document.title = '获得焦点';};</code>
I have written one using nodejs socket.io before. If you search directly, you will find many examples written by others: http://www.open-open.com/lib/...
Correct answer upstairs.
Case address: http://www.workerman.net/
Websocket is definitely not implemented through ajax.
Using websocket is definitely the most perfect, and can be implemented through frameworks such as workerman, react, and swoole.
You can also use long polling, but it consumes more resources. But the implementation cost is lower than websocket .
There is also real-time polling, which has the lowest implementation cost. However, the efficiency is definitely the lowest. SF message reminders use scheduled polling

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
