Errors don't work in cron jobs?

function shutDownFunction($id) {
    $error = error_get_last();
    if ($error['type'] == 1) {
		//my stuff to do on error here


This works when ran through a browser, but not when ran as a cron job. Any reason why? How can I make it work?

It might depend on what ‘my stuff to do on error here’ is. Display an error on screen?

I run a mysql query there. It works through a browser, and other queries outside the function work even through cron jobs. It is just that the shutDownFunction is never triggered in a cron (I think).

Anyone have any ideas?

A php script run through cron job is the same kind of GET request as you perform in your browser so theoretically everything should work the same. The only differences are $_SERVER variables which will be different: the remote IP will be the same as the local one, the user agent string will be different, no cookies, etc. Are you sure your script is not doing something different depending on some of these variables?

I used to have a problem with cron jobs because my script compared $_SERVER[‘SERVER_ADDR’] to $_SERVER[‘REMOTE_ADDR’] to determine which database to connect to (the live db on the site or the development db on localhost). When run through a cron job the script thought it was the development server because these two IP’s were the same. I had to change the condition to something else to make it work.

I don’t use either of those on the page. I have other database queries that run fine on the page through a cron. It is simply the shutdownfunction that doesn’t get triggered, either that or error_get_last() is blank. Any ideas?

How is your cronjob set up? Could you paste here? Sometimes for running PHP in cronjob you need to change the current directory by chdir function.

I am using the default “crontab -e” file. I am running php with “/usr/local/bin/php -q”. The cronjob runs the script, and everything in the script, except for the error part.