¿Verificar si mi archivo php se está ejecutando o no? Si no ejecuta el archivo

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

2 Respuestas

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.

contestado el 24 de mayo de 14 a las 14:05

if i use cron job to run this file,how much will be my BandWidth will be affected-running each minutes.? - BeingShashi

Your bandwidth will not be affected at all. The bandwidth measures the data volume transferred via a network interface. The cron job requests locally using the loopback interface. That has no effect on your bandwidth limit whatsoever. That said I want to emphasize: the cron job should run on the system where that php file is installed, not on some client system! - arcascha

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.

contestado el 24 de mayo de 14 a las 14:05

thanks for your reply ,but i am not looking for manual solution. is there any way written within PHP Code or using shell script. - BeingShashi

I am not sure how you see this as a "manual" solution. Once you set it up, it will no longer require any manual intervention. Similar to setting up a cron job. - dmullings

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.