Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/142539-alarm-systems-cron-and-server-load/
Share on other sites

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.

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 ().

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.