How to use a long survey or Ajax Push on your website

I want to know how to use ajax push. I learned from various web articles that Ajax push can be obtained using several programs, such as COMET, APE (AJAX PUSH ENGINE), etc. But I want to know if there is an easier way to use it and which language is used to implement ajax push. because in the articles that I saw. they use java. which I did not recognize :( Therefore, I would like to know if there is something like: javascript on your server that sets the interval for a specific element, and then if any changes are detected, repeat it with php. for this I tried it for a week already. I tried to use regular ajax and php using intervals, but could not get the result. Thank you. PS: Please show me an easy way to use it with an example or something like that.

+3
source share
2 answers

I used a very simple flash based approach a while ago

I turned on a small transparent flash drive of 1px * 1px size on my page, which opened the socket for the server to which it sends AJAX requests. The server receives an AJAX request and responds to a flash socket

The flash simply opens javascript: url, which calls the onreceive event handler, so you will not open a new page, but run javascript on the current page

+1
source

If you want to use PHP as the underlying technology, then this will be a tough fight. Read this question on concurrency - how to implement event listener in PHP for more information.

The simplest solution for PHP developers, in my opinion, is to use a hosted real-time service, for example Pusher - for whom I work. This means that you don’t need to worry about installing or maintaining your web infrastructure in real time, and most importantly, you don’t need to worry about your server processing persistent concurrent connections. You use the Pusher JavaScript library, which connects to Pusher from a web browser, maintains a constant connection and receives any updates that push it, and the PESTER REST API to publish data from your PHP application through Pusher to connected clients.

It starts with a Pusher guide on Nettuts + , which has been very popular and a good starting point for anyone using PHP.

If you really want to host your own real-time infrastructure in PHP (don’t say that I didn’t warn you), you can see How to implement PHP with Comet and PHP WebSockets (there is also a github project with recent activity called php-websocket -server ).

+2
source

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


All Articles