Search code examples
phperror-handlingcroncron-task

Handling php script errors, while executing it by cron


I have a MVC framework with a controller in it. A controller downloads images from server. I need to refresh my database with those images every 5 minutes. So, I planned to create php script which downloads the file and persists it to my database. In order to do this every 5 minutes. I will be setting up Cron job.

Now the question is,

  1. What is the best practise to handle errors inside php script?

    Because Cron will keep executing at every 5 minutes without knowing that the last queried image is already lost and not being saved.

  2. How do I notify myself that something unusual happend and I need to maintain the DB consistency by my self (Which I don't mind for few instances).


Solution

  • What is the best practise to handle errors inside php script? Because Cron will keep executing at every 5 minutes without knowing that the last queried image is already lost and not being saved.

    use asserts as described here: http://php.net/manual/en/function.assert.php

    How do I notify myself that something unusual happend and I need to maintain the DB consistency by my self (Which I don't mind for few instances).

    use mail() in asserts