skip to Main Content

I am creating a cronjob in cPanel that runs a simple PHP script.

If my CronJob fails then the server automatically sends me an email which is good, but how can I trigger this error from my PHP script?

Is there a way like with exit() or similar?

2

Answers


  1. Explicitly exit from the program and pass a valid exit status that is not 0 so that cron will recognise it as exiting in an error state.

    fwrite(STDERR, "This is a fatal error!" . PHP_EOL);
    exit 1;
    
    Login or Signup to reply.
  2. I don’t have tested yet but there is a function on php for trigger custom error.
    Take a look there –> https://www.w3schools.com/php/func_error_trigger_error.asp

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search