futurshox Posted January 26, 2009 Share Posted January 26, 2009 I am building an alarm system which reacts to data files being received via FTP at 2-minute intervals. An existing script runs in cron every 2 minutes which reads the data file and inserts the data into a database. My alarm system reads the database and examines the latest data against pre-set tolerance limits. If the data is outside tolerance then emails need to be sent to recipients whose addresses reside in a database. They are split into two groups. Each group can set their own tolerances, and each person may belong to one of three shifts so messages need to be filtered to the right people. There will be somewhere between 50-100 people. User settings also include time intervals. Repeated instances of out-of-tolerance data should result in repeated alarms at pre-set intervals (in minutes). Likewise, once data has been within tolerance for a separate pre-set time then the all-clear should be sent. Currently I have this running every 10 minutes and it is working OK. However I have been asked to make it run every 2 minutes so the latest data is always examined. I am concerned about putting load onto our (shared) server and therefore I have some questions: - How long does it take to send 100 emails? - What happens if the script takes longer than 2 minutes to run, does it start overlapping jobs in cron? - Should I split the alarm script so that the triggers are part of the incoming data script (which runs at 2-min intervals anyway) and keep the repeat alert/all clear stuff in a separate script that runs every 5 minutes instead? - Is it really bad to run a cron job every minute? I may be asked to do this in future; my gut feeling says "don't do it!" but am I being too paranoid? I'm just really worried that if a script runs away, the next one will bog down, then the next one and so on.... - Is it possible to tell when a script is running, or has stopped running, in PHP? Could I run a script that said "Only run this include() file if there are no other instances of this script running"? Any suggestions/insights would be very appreciated! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/142539-alarm-systems-cron-and-server-load/ Share on other sites More sharing options...
jimbo_head Posted January 27, 2009 Share Posted January 27, 2009 Why not have a cron entry to check if your script is running every 2 minutes and if it is not then start it. The impact of the script depends on you system and on your script. You should first set up another script to monitor server load before you turn on this script and after you turn it on. This way you can prove what impact your script is having on the system. Quote Link to comment https://forums.phpfreaks.com/topic/142539-alarm-systems-cron-and-server-load/#findComment-747671 Share on other sites More sharing options...
futurshox Posted January 27, 2009 Author Share Posted January 27, 2009 Jimbo_head, thanks for your reply. How do I see if a script is running, and how do I monitor server load? Does it require some kind of exec() command? Quote Link to comment https://forums.phpfreaks.com/topic/142539-alarm-systems-cron-and-server-load/#findComment-748020 Share on other sites More sharing options...
jimbo_head Posted January 28, 2009 Share Posted January 28, 2009 Hi futurshox To see if your script is running I would write a shell script and cron that every two minutes. This script will use ps and grep to check if your script is running and if it is not the it will run it. If you dont use nohup and send it to the background then it defeats it purpose. #!/usr/bin/ksh ps -ef | grep <path_to_script> RES=$? if [ $RES -eq 1 ] then nohup <path_to_script> & To monitor server load you would use an OS command such as top or glance depending on your OS. If this monitoring is to be done from within the php script then yes indeed you would need to use exec (). Quote Link to comment https://forums.phpfreaks.com/topic/142539-alarm-systems-cron-and-server-load/#findComment-748521 Share on other sites More sharing options...
jimbo_head Posted January 28, 2009 Share Posted January 28, 2009 Sorry there was a slight error in the code I posted in the previous post I forgot to close the if statment it should be. #!/usr/bin/ksh ps -ef | grep <path_to_script> RES=$? if [ $RES -eq 1 ] then nohup <path_to_script> & fi Quote Link to comment https://forums.phpfreaks.com/topic/142539-alarm-systems-cron-and-server-load/#findComment-748525 Share on other sites More sharing options...
futurshox Posted January 30, 2009 Author Share Posted January 30, 2009 Thank you very much, Jimbo_head. Quote Link to comment https://forums.phpfreaks.com/topic/142539-alarm-systems-cron-and-server-load/#findComment-750681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.