PHP long polling, without excessive database access

前端 未结 6 1276
無奈伤痛
無奈伤痛 2021-01-02 17:26

I\'ve always enjoyed the idea of long polling; on my development server I\'ve played with various notification / new post systems, each using javascript to hold a connection

相关标签:
6条回答
  • 2021-01-02 17:42

    If your specific problem is that you're trying to avoid notifying events through a database, you should probably be looking at using shared memory or semaphores.

    Instead of continuously polling the database, you would instead monitor the shared memory. When something writes to the db (I'm assuming some sort of message queue), you can flag the event via the shared memory. The listening code would detected this, and only then establish a db connection to retrieve the message. Alternatively, you could use shared memory to entirely replace the use of the database.

    The reference for the php semaphore and shared memory functions is here - http://uk.php.net/manual/en/ref.sem.php

    0 讨论(0)
  • 2021-01-02 17:44

    data cache, I like the one from Zend Server, it dramatically reduced pulling from database

    0 讨论(0)
  • 2021-01-02 17:47

    WebSockets

    ...

    When it's actually fully supported ;)

    0 讨论(0)
  • 2021-01-02 17:55

    Whenever you Insert or update your database create a cache for that field of the database. You can use any simple PHP based cache (http://hycus.com/2011/03/31/hcache-a-cache-system-for-php/).

    Then you can poll that cache continuously using JQUERY.

    0 讨论(0)
  • 2021-01-02 18:01

    I would use some nosql to notify there is new data. Redis has pub/sub and a blocking list.

    You can also use, for example, memcache and create a new key when the data is available.

    0 讨论(0)
  • 2021-01-02 18:03

    Can look into having a flash movie in the background that maintains a continuous connection with the server using sockets. Java also supports sockets so can also be a java applet embedded in your page.

    0 讨论(0)
提交回复
热议问题