9 Replies - 3725 Views - Last Post: 26 March 2013 - 07:37 AM Rate Topic: -----

#1 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Live data - possible?

Posted 18 March 2013 - 03:21 AM

Good morning, D.I.C.

I previously asked a question, although I can't seem to find it - I wanted to use it for reference. It appears I'll have to ask the same question again.

I'm wanting to get data as it appears, a fine example which most will understand is Facebook's notification system. As soon as something happens, you receive a notification letting you know what happened. I'm not wanting to make a notification system, as such, I just wondered how they'd done it.

I vaguely remember someone mentioning sockets; I tried that method earlier and I just get an error that the "socket_create" function doesn't exist, so I'll be looking for other methods.

I'm currently using jQuery to get a request every two seconds (with a few people on at the same time, the "Impressions" on my website analytic's are going crazy! I hoped there would be something a little more user-friendly. If not, I'll have to either stick with jQuery or use a META refresh - both are ugly in their own way.

Thanks for any help, always appreciated.

~huzi

Is This A Good Question/Topic? 0
  • +

Replies To: Live data - possible?

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3635
  • View blog
  • Posts: 5,756
  • Joined: 08-June 10

Re: Live data - possible?

Posted 18 March 2013 - 04:29 AM

Hey.

The modern answer to this question is: WebSockets. It's a HTML5 technology that allows two-way communications between Javascript and a server. With that your server can push messages down to the Javascript code as needed, without Javascript having to initiate a request.

Prior to WebSockets, in older browsers that don't support it, things get a little more complicated. The way the HTTP protocol is set up, there is technically no way for the server to send data to the client without the client asking for it. You'd need to do the whole AJAX on a timer thing, or refresh the page.

However, there are methods you can employ to "exploit" the HTTP protocol so that you can have the server send messages down to the client. Google the term "long polling" and you should get a few useful hits. - This tends to come with a price, though, since you are essentially abusing the HTTP protocol in a way it wasn't intended. WebSockets would be a far preferable option, if the browser support isn't a problem for you.
Was This Post Helpful? 2
  • +
  • -

#3 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: Live data - possible?

Posted 18 March 2013 - 04:35 AM

Beautiful answer, thank you very much!

~huzi

This post has been edited by Dormilich: 24 March 2013 - 12:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: Live data - possible?

Posted 18 March 2013 - 05:06 AM

After some research, I have discovered that WebSockets allow my web page to communicate with my personal computer - am I right?

I merely wanted to load another page without it classing as an impression each time.

Many thanks

~huzi
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3635
  • View blog
  • Posts: 5,756
  • Joined: 08-June 10

Re: Live data - possible?

Posted 18 March 2013 - 07:04 AM

Yes, you are correct. It just makes a connection where the server and client can pass data between them in both directions.

I'm not following you exactly on this. What classifies something as an impression? In my limited experience with Google's Analytic tools, that word is used in relation to how search results are displayed. That doesn't seem to be the case here though.

However that may be, a WebSocket can pass whatever data you need. If you need a page sent to the client, the socket can do that.
Was This Post Helpful? 0
  • +
  • -

#6 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: Live data - possible?

Posted 23 March 2013 - 04:55 AM

Sorry, I'll do my best to explain.

I have one web page, which returns data - it has no other purpose, it has no interface, just a white page. When the correct variable are passed, it returns data, respectfully.

I have a script on which is included on each page, which sends data to the aforementioned page, and deals with the data accordingly. I have this script request this page every 5 seconds, or so. This all worked fine.

I checked on my Site Analytic's and the most popular webpage on my website was the page which returns the data - which is false, because that's only used to return data.

I hope this helps you to better understand my predicament.

Many thanks

~huzi

This post has been edited by Dormilich: 24 March 2013 - 01:00 AM

Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3635
  • View blog
  • Posts: 5,756
  • Joined: 08-June 10

Re: Live data - possible?

Posted 23 March 2013 - 07:21 AM

OK, I see. Why is that page showing up in the analytics results? I'll admit that I'm not very knowledgeable about Google Analytics, but I was under the impression it only recorded pages where the GA script itself was included. Does it also track AJAX requests from other pages it's included on?

What format does the script return the data in? Is it a HTML page or some sort of data format, like JSON or XML?
Was This Post Helpful? 0
  • +
  • -

#8 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: Live data - possible?

Posted 26 March 2013 - 06:12 AM

View PostAtli, on 23 March 2013 - 02:21 PM, said:

OK, I see. Why is that page showing up in the analytics results? I'll admit that I'm not very knowledgeable about Google Analytics, but I was under the impression it only recorded pages where the GA script itself was included. Does it also track AJAX requests from other pages it's included on?

What format does the script return the data in? Is it a HTML page or some sort of data format, like JSON or XML?


It's not Google Analytic's, just analytic's provided by my host (1and1). My analytic's records all my AJAX requests; the format returned is HTML.

I hope this is some help; I could really do with proper analytic's, where AJAX are included.

Many thanks

~huzi

EDIT
Typo corrected.

This post has been edited by huzi8t9: 26 March 2013 - 06:13 AM

Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,210
  • Joined: 23-August 08

Re: Live data - possible?

Posted 26 March 2013 - 07:34 AM

Quote

I hope this is some help; I could really do with proper analytic's, where AJAX are included.


Did you mean AJAX is NOT included? Because you seem to say that the AJAX calls are what is causing your issue.

It really sounds to me like you should be talking to 1&1 about this. I don't think it's anything we can help with. It sounds like they log every request to your server and present it via analytics. This is the problem with hosting plans like this; you give up control for ease of use and price.
Was This Post Helpful? 1
  • +
  • -

#10 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: Live data - possible?

Posted 26 March 2013 - 07:37 AM

View PostJackOfAllTrades, on 26 March 2013 - 02:34 PM, said:

Quote

I hope this is some help; I could really do with proper analytic's, where AJAX are included.


Did you mean AJAX is NOT included? Because you seem to say that the AJAX calls are what is causing your issue.

It really sounds to me like you should be talking to 1&1 about this. I don't think it's anything we can help with. It sounds like they log every request to your server and present it via analytics. This is the problem with hosting plans like this; you give up control for ease of use and price.


Sorry, yes - I do not want AJAX calls included.

I had a look a Google Analytic's and have not implemented that into my website - included the GA code on every page I wanted to track.

Thanks for your suggestions and continues support, it's very much appreciated.

~huzi
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1