質問

I'm finishing a JQuery plugin, and I need to collect usage data of some activity while the plugin is active. This data needs to be stored remotely on my servers.

However, I'm trying to find the best approach to do this. It would be similar, I guess, to how web analytics data is collected. I see two options right now and I have outlined the basic steps below.

A. AJAX - With this approach:

  1. I use JQuery to setup an Ajax request in my JQuery Plugin to POST data to a server
  2. I setup this server to capture the data that was POSTED, and then use PHP to insert into a database table

B. SOCKETS - With this approach:

  1. I sign up for a service like PubNub
  2. I use the PubNub Javascript SDK in my JQuery plugin to "publish" a message to a given "channel"
  3. I set up a dedicated server or cloud server, and using SSH to login, install a web server + database + PHP, and make sure it works ok
  4. I create my PHP script (using the PubNub PHP SDK) to "subscribe" to the pubnub "channel" my plugin will publish messages on, and then setup the mechanism to capture the data from the message and insert into a database table
  5. I set up supervisord to daemonize my php script, and then start the daemon since I need a long-lived PHP process to run the PubNub Subscribe feature via a server.

I prefer A because it's the simplest option for me, I can use any hosted MySQL/PHP server to get it done with minimum hassle. However, I'm concerned how performant this approach would be when the plugin is being used in thousands of different web sites, or a few very busy websites, with potentially 10 - 100 database submissions per second on my remote server.

Would it make more sense to use the B approach with sockets instead, at a potentially much higher cost because of the PubNub subscription I would require to pull this off. Also, being that I don't need asynchronous connectivity as I need to make only one request per user, I'm thinking sockets might be overkill compared to the trusty ol' HTTP request directly to my server (as opposed to a message being sent through PubNub, and then to me).

What really is the best way to pull something like this off?!

Thanks in advance.

役に立ちましたか?

解決

You are correct, sockets are overkill. Even Google Analytics uses HTTP requests to send data. These requests aren't required to be timely (e.g. milliseconds don't matter) so there's no reason to open a socket.

他のヒント

Option A for sure. Additionally check out something like AppFog if you are really worried about tons of hits to your PHP script, they offer quite a bit for free and that could take the load off of your server if it gets to be an issue.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top