1

I'm developing a web app using Symfony 2.8. I need to use the Pingdom API to obtain information about certain websites which are being monitored by Pingdom.

I was able to do a request to obtain the checks of a certain website, using the app key, etc, but I need to create a real-time application, that is, my web app should constantly do requests using the API to obtain new values for these checks.

I've been thinking at which technologies should suit better for this purpose, but honestly, after some research, I still don't know what to use.

I've thought I could use websockets directly, but, as far as I've understood, websockets "listen" to events, and in this case there's no event (right?), i.e. this should be a "polling system".

I've looked at pusher, but this only seems to be a wrapper around websockets.

Note:

  1. I'm aware of the webhooks of Pingdom, but to use them they need to know my IP address (as far as I've understood how a webhook works), but of course I also want to work locally, and thus a "polling" system instead of a "pushing system" is the way to go.

  2. I've already a controller that does the requests to the API, and the only thing I should probably do is do requests to this controller (from the client-side...), but I'm not sure since I've never done this.

  3. Please, only people that have experience with the subject, i.e. with using APIs and in creating this kind of real-time apps where APIs of third-party providers are provider.

  4. I'm aware of that fact I could use like a setTimeout and do a XmlHttpRequest to my controller, but, again, I really don't know if this is the "standard" way of doing it.

  5. I would prefer proper tools, instead of the raw ones, but just in case the first ones are well-maintained and work well.

  6. The method doesn't have to be restricted to this particular situation, indeed this actually should be a method whenever there's the need for making repeated requests using any API.

I know this is a long question, which actually could be summarised almost in one line, but I really wanted to point out my situation, and my requirements, lets say.

nbro
  • 15,395
  • 32
  • 113
  • 196

1 Answers1

2

You may consider writing a console command doing the same thing as your controller, so you can call it from the console.

Then, if you are on a Linux distribution, you can use crontab to call your console command regularly as often as you want

If you are on windows, you can use planified tasks

Special recommendation : if you need to keep your controller aside from the command, you may consider writing the logic calling the API in a service, in order to factorize your code.

Hope it helps

Xavier Norbal
  • 476
  • 4
  • 8
  • Maybe I was not clear, but how can I update the client-side app (webpage) using this method? – nbro Jul 21 '16 at 08:56
  • A symfony console command has access to the service container, so basically you are able to do everything you want, i.e. insert data in your DB – Xavier Norbal Jul 21 '16 at 08:57
  • The point is, since this is a client-server web application, I guess that the process of repeatedly asking for updates must be done on the client-side, because there's no way for the server to know to which client it should return the page, that's why maybe my problem is just a matter of `setInterval` or `setTimeout` (with JS), but I'm not sure it's a good idea yet... – nbro Jul 21 '16 at 09:01
  • OK, I think I understood your situation. You have a front page where your data is displayed, but you want your data to be auto updated when the user is on your page. So yes, on that side, you might call a setInterval. But i'ts not user friendly to call to external APIs for data when processing a user Request, plus if you hav many Users on the page, it is as many requests to PingDom API. So I recommend using a console command to store data from pingdom API on your DB, and then, when a user asks for an update, fetch the data from your DB instead of the API – Xavier Norbal Jul 21 '16 at 09:02
  • Plus, pingdom API is surely limited in terms of call/minute or /day, so it would help you not cross that limit – Xavier Norbal Jul 21 '16 at 09:08
  • The problem, from what I read from the Pingdom API's docs, is that in general the clients of that API should not take as granted the fact all previously returned fields as JSON are present again... – nbro Jul 21 '16 at 09:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117895/discussion-between-xavier-norbal-and-nbro). – Xavier Norbal Jul 21 '16 at 09:14