Jump to content

Send email on file date time condition


A_tom

Recommended Posts

On my home network, I have a computer that is uploading data to my website. One file being uploaded is just the date and time, and this happens about once every five minutes. I wish to create a php script that will test this file and send me an email when the file is no longer updating. This will tell me when my home computer has lost internet connectivity or has stopped working. There seems to be plenty of examples of php script that would do the file test. How do I get the script to execute on a timer?

Link to comment
Share on other sites

You will likely find your answer under PHP Other Services.  See  PHP Event.

Roddy

P.S. If this helps pass your cursor over the heart and click the trophy.

Link to comment
Share on other sites

This isn't really event-driven, this is just running a script on a schedule.  On Linux servers, you use cron to create a task to run on a schedule, on Windows servers you use the task scheduler.  If it's a cron job you typically just tell it to execute PHP and pass the filename to your script, e.g.:

php -f /path/to/script.php

You can have it run as often as once per minute, or however else you'd like.  If you rent a server from a host then you can probably set up cron jobs in your control panel somewhere.

Link to comment
Share on other sites

4 hours ago, justsomeguy said:

This isn't really event-driven, this is just running a script on a schedule.  On Linux servers, you use cron to create a task to run on a schedule, on Windows servers you use the task scheduler.  If it's a cron job you typically just tell it to execute PHP and pass the filename to your script, e.g.:

 


php -f /path/to/script.php

 

You can have it run as often as once per minute, or however else you'd like.  If you rent a server from a host then you can probably set up cron jobs in your control panel somewhere.

Right, I was planning on it being a cron job. I was mainly concerned about figuring out what the php script would look like.

Link to comment
Share on other sites

If you're trying to check the file, then use something like file_exists and file_get_contents to get the data in the file, and check it however you want to.  If you can get the file's last modified date that will probably tell you what you need to know.  You can also use the SPL.

http://php.net/manual/en/class.splfileinfo.php

http://php.net/manual/en/class.splfileobject.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...