Real time and php?

I am starting to work in real-time applications (e.g. Chat, MMORPG), but I am well versed in php and ajax. I programmed the chat using php and ajax (Interval 1000ms). After that, my site became very difficult due to a lot of pressure on the server!

I need information about reducing pressure on the server.

early

+7
source share
8 answers

Look no further than PubNub!

PHP client libraries are available at https://github.com/pubnub/php (including composer)

and over 50+ (including javascript) can be found here: http://www.pubnub.com/developers/

See if you qualify for a free plan: http://www.pubnub.com/free-evangelism-program/

+3
source

Look for a long ajax poll

It requests only once a minute (requests are not 60 / min, but 1 / minute)

+1
source

You can try converting chat into a socket based web application. I don't know about performance differences between using AJAX or using sockets, but my sockets for this sound more logical to me. :)

+1
source

You might want to cache the results. Setting memcached cache (key => value) can reduce the load on the database.

When a new request arrives, your application requests memcache if the value it is looking for is in the cache. Otherwise, set your database engine for the value, return the value to the user, and cache it next time.

+1
source

An interesting PHP library that provides developers with tools for creating real-time applications, bidirectional applications between clients and servers via WebSockets: http://socketo.me/ p>

+1
source

As far as I know, there are several libraries for creating non-blocking and real applications, such as chat and real-time game.

+1
source

You can also take a look at the ajax push engine for real-time streaming (they claim it scales very well). http://www.ape-project.org/

0
source

Even the question is old, I would like to share with you what I found.

WebSockets is now supported by all major browsers. Thus, the easiest way to create a system in real time is to use WebSockets. But PHP does not support WebSockets by default.

But there is Node.JS to make the task easier. Do I need to reprogram my site in Node.JS? Not! I found a smarter solution that helps you use Node.js with PHP only for real-time communication.

How it works?

  1. A user connects to a WebSocket server written in Node.js
  2. When we have a notification or update in PHP, we notify the Node.js server through an HTTP POST request
  3. Node.js HTTP server processes the request and sends a response to connected users via WebSockets.

See an example of creating a live chat application with PHP and Node.js.

0
source

Source: https://habr.com/ru/post/895374/


All Articles