0

Possible Duplicate:
Run php script as daemon process

I'm developing a web app working closely with the Twitter API. Basically everytime an user clicks on a specific button I need to record this action into my database(1) and post a tweet on the user's behalf via the API(2). Since those actions are somehow connected they must occur at the "same time" or more precisely if (1) is successful then post the tweet (2). Adding a row in the local database (1) is an instant, happens in <1ms or less but the twitter API is slow, so it can take above 600ms to succeed and that is not acceptable for the end user to wait that long, not to mention that sometimes it could be slower or even worse, timeout.

SO I was thinking if there's a way to have a PHP script acting like a server accepting requests and queue them as they come. Sure I could launch a script every single time but imagine having 100 scripts launched together, this would cause an enormous memory usage and overhead to kill them as they finish their work.

Community
  • 1
  • 1
Sandro Antonucci
  • 1,683
  • 5
  • 29
  • 59

1 Answers1

1

This is the "bible" of PHP daemons tutorials.

http://kvz.io/blog/2009/01/09/create-daemons-in-php/

Beware, check the Legacy Warning.

napolux
  • 15,574
  • 9
  • 51
  • 70