0

I am trying to ping my database in a regular intervals of time so I can check the status of a column. Like in every 3 seconds I want to know the status of a column.

Morne
  • 1,623
  • 2
  • 18
  • 33
user2926947
  • 47
  • 1
  • 7
  • 2
    What you want to know from that ? – Abdul Manaf Mar 07 '14 at 11:15
  • 1
    Would it not be easier to log when changes to that column occur? – SubjectCurio Mar 07 '14 at 11:16
  • Like i have a database where a column name is 'status', inside it the value will be 0 and 1, so i need to know when it comes 0 and when it comes 1. – user2926947 Mar 07 '14 at 11:18
  • Why dont u use a trigger or something like that, is this for ur application or for testing purpose?? – Amarnath R Shenoy Mar 07 '14 at 11:20
  • You have a column, inside a table, inside a database – Strawberry Mar 07 '14 at 11:20
  • Write a small PHP script that queries the database, and outputs a value related to what was returned from the database. Use javascript to access your PHP script, retrieve the result and do whatever you want to do with the result. Wrap the javascript portion in a timed loop, so it accesses your PHP script every 3 seconds. – SubjectCurio Mar 07 '14 at 11:22
  • @MLeFevre yes i am doing the same, but got stuck in some where, i used a php to write the query and used JS to call the function. now how should i call in loop – user2926947 Mar 07 '14 at 11:25
  • Use setInterval to create the loop setInterval(function(){checkStatus()},3000); – Morne Mar 07 '14 at 11:26
  • @user2926947 `setInterval(function(){},3000);` – SubjectCurio Mar 07 '14 at 11:27
  • 3
    What ever is your purpose , U should note that calling ur db all now and then is not a good practice, actually is a very bad practice, try to deal these things in your server itself rather than bringing them to client side, some thing like in every 3 seconds means 20 db calls a minute from a single client , think about ur app being used by a large group, Thats really something you should consider – Amarnath R Shenoy Mar 07 '14 at 11:27

2 Answers2

0

You can write a php script to retrieve that value and run that script at regular intervals i.e. 3 seconds in your case .

something like this for local

*/3 * * * * /usr/bin/php -f /var/www/cron.php

yantrakaar
  • 374
  • 3
  • 15
0

If you need to call your db every 3 seconds you can use a javascript something like this setInterval(function(){},3000); to call your analysing function , but this isnt a good practice. If your purpose is to know the time and context of ur field value being changed you have lot of other ways like using triggers is the best solution for this purpose, Check this link to know more about triggers

https://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html

also go through

Are database triggers evil?

hope this will help you.

Community
  • 1
  • 1
Amarnath R Shenoy
  • 5,121
  • 8
  • 24
  • 32