i have written one PHP twitter streaming code,which continuosly search or filter live tweets. i have question that , if suppose file stops because of any network failure,so there should be functionality that which identifies that ,the file has stopped , RUN it again. and if already running do nothing.any help?
preguntado el 24 de mayo de 14 a las 14:05
You are looking for some kind of "locking mechanism". Many approaches are to be found in examples on the internet. The easiest probably is to implement a "trigger" event, typically a cron job firing the script every minute. First thing done by the script is to check if there is another instance running. if so it terminates itself, if not it continues with its real purpose. So the critical part is the detection step. Different alternatives are available again, the easiest one is to write a lock file holding the scripts process it. Then a subsequencially started script instance can not only check the existance of such a lock file, but by reading the process id it can also test it against the process table to check if that prior script is still executing. That is a robust and often seen pattern.
If you are on linux you can use God http://godrb.com/ which is a process monitoring tool. You should be able to monitor the php script and then take action if it stops. The action could be to restart the script and send an email notification. Will take some configuring, but it should work for you.