-2

I was wondering how I would go about making a script that looped infinitly on my server.

For example, lets say I wanted my script to check my database, and if there are new entries, it tweets them.

Would I be able to use purely php an mysql for this, or would I have to look into something like node.js? Thanks to anyone who can help.

Charles
  • 48,924
  • 13
  • 96
  • 136
  • You're talking about "Comet". Have a look at http://stackoverflow.com/questions/603201/using-comet-with-php – Scopey May 02 '14 at 03:28
  • you can use `setInterval()` method and then `ajax` to fire a request to server – ashishmaurya May 02 '14 at 03:34
  • Does it *really* need to be that frequent? I have had good results with a simple cron job that hits a PHP script every ~5 minutes or whatever frequency is most suitable. – Marty May 02 '14 at 06:13

1 Answers1

1

Usually, a "script that loops infinitely" is an indicator something could be done better (though not always).

In this case, you can put a trigger in your database, so if there is a new entry, it runs an external program of your choice.

Here's someone who shows how to do exactly that, so I can be lazy and claim the credit :)

http://crazytechthoughts.blogspot.co.nz/2011/12/call-external-program-from-mysql.html

AMADANON Inc.
  • 5,391
  • 18
  • 30