最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PHP - getting real time data from the database - Stack Overflow

programmeradmin2浏览0评论

I've been trying to get data from my database by php and PDO. Before I ask the question, I want to show you the part of the database that i want to get in real-time:

the data I want to get is: CPU_util in real time.

** CPU_util moves between 0 to 100

In the website I'm using the plugin: highcharts in order to display the CPU_util. The chart the I picked up is this (link to the chart):

My question is:

How to get the data in CPU_util from the database and put it in the chart in real time?

(X axis should be as it is (the current time) and the Y axis moves between 0 to 100)

What I've been trying so far:

I did some coding with ajax, but after some tries the website blocks me, because I passed the number limit of http request (2000 requests).

I've been trying to get data from my database by php and PDO. Before I ask the question, I want to show you the part of the database that i want to get in real-time:

the data I want to get is: CPU_util in real time.

** CPU_util moves between 0 to 100

In the website I'm using the plugin: highcharts in order to display the CPU_util. The chart the I picked up is this (link to the chart):

My question is:

How to get the data in CPU_util from the database and put it in the chart in real time?

(X axis should be as it is (the current time) and the Y axis moves between 0 to 100)

What I've been trying so far:

I did some coding with ajax, but after some tries the website blocks me, because I passed the number limit of http request (2000 requests).

Share Improve this question edited Mar 25, 2016 at 11:21 Your Common Sense 158k42 gold badges225 silver badges368 bronze badges asked Mar 25, 2016 at 11:14 iYonataniYonatan 9663 gold badges11 silver badges26 bronze badges 13
  • Your question and title are two different things. – amanuel2 Commented Mar 25, 2016 at 11:18
  • 1 Websockets is better suited to achieving long polling/real time data. – MackieeE Commented Mar 25, 2016 at 11:18
  • It's a bad idea to request data from a database or other persistant data storages if you want that data realtime. If you really want this, your best chance is to set up a stream (long get requests) to some server. The server then should listen to the source that outputs the data for CPU_Util. – Glubus Commented Mar 25, 2016 at 11:19
  • @AmanuelBogale Edited – iYonatan Commented Mar 25, 2016 at 11:20
  • 1 I have never implemented something like this, but WebSockets and the long get requests (it has a name, but I cant be bothered to look for it) are widely used nowadays, so you shouldn't have too much trouble finding a way to do this. About the CPU, you need to have direct access to the source outputting the CPU_util data, so instead of sending it to the mysql table, you need to direct it to the stream that you need to setup. – Glubus Commented Mar 25, 2016 at 11:23
 |  Show 8 more ments

1 Answer 1

Reset to default 3

Realtime PHP is a pletely different animal pared to 'normal' web apps. As already suggested, websockets or http-long-polling is the way to go.

The big issue to tackle is dealing with the HTTP request limit and not crashing your server and not starting a php(-fom) thread for each request you are making. To achieve this you will have to rethink your architecture a bit.

To achieve realtime php you'd want non-blocking evented php on the server (nodejs style). In the world of php the most used library for achieving this is Ratchet.

If you want to learn more:

  • http://socketo.me/docs/
  • http://www.sitepoint./how-to-quickly-build-a-chat-app-with-ratchet/

Also, if you're really doing ALOT of calls to mysql, you may want to move this data to a separate high performance db like Redis

发布评论

评论列表(0)

  1. 暂无评论