When running CRON, 'require' fails silently

cron job time
crontab example
crontab logs
how to set cron job in linux server step by step
how to execute cron job in linux
crontab viewer
interpret crontab

I have a backup script that runs from the browser without a problem. It extracts data from the database and writes it to a ZIP file that's under 2MB .

It mostly runs from the server, but it fails (silently) when it hits a particular line:

require ('/absolute-path/filename');  // pseudo filespec

This is one of several such statements. These are library files that do nothing but 'put stuff in memory'. I have definitely eliminated any possibility that the path is the problem. I'm testing the file with a conditional is_readable(), output it, and sent myself emails.

$fs = '/absolute-path/filename'; // pseudo filespec
if (is_readable ($fs) ) { 
    mail('myaddress','cron','before require'); // this works reliably
    require ($fs); // can be an empty file ie. <?php ?>
    mail('myaddress','cron','after require'); // this never works.

When I comment out the require($fs), the script continues (mostly, see below).

I've checked the line endings (invisible chars). Not on every single include-ed file, but certainly the one that is running has newline (NL) endings (Linux-style), as opposed to newline + carriage return (NL CR) (Windows style).

I have tried requiring an empty file (just <?php ?>) to see if the script would get past that point. It doesn't.

I have tried calling mail(); from the included script. I get the mail. So again, I know the path is right. It is getting executed, but it never returns and I get no errors, at least not in the PHP log. The CRON job dies...

This is a new server. I just migrated the application from PHP 5.3.10 to PHP7. Everything else works.

I don't think I am running out of memory. I haven't even gotten the data out of the database at this point in the script, but it seems like some sort of cumulative error because, when I comment out the offending line, the error moves on to another equally puzzling silent failure further down the code.

Are there any other useful tests, logs, or environment conditions I should be looking at? Anything I could be asking the web host?

This usually means that there is some fatal error being triggered in the included file. If you don't have all errors turned on, PHP may fail silently when including files with certain fatal errors. PHP 7 throws fatal errors on certain things that PHP 5.3 did not, such as Division by Zero. If you have no access to server config to turn all errors on, then calling an undefined function will fail silently. You can try debugging by putting die('test'); __halt_compiler(); at the beginning of a line, starting from the top, on the line after the first <?php tag and see if it loads. If it does slowly displace line by line (though don't cut a control structure!) and retest after each time and when it dies you know the error is on the line above.

How to use cron in Linux, Here's what I did, and it seems to work in this situation. At least, it shows me an error, whereas running from the command line as the user doesn't show the error. The software utility cron is a time-based job scheduler in Unix-like computer operating systems. Users that set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals.

I believe the problem may be a PHP 7 bug. The code only broke when it was called by CRON and the 'fix' was to remove the closing PHP tag ?>. Though it is hard to believe this could be an issue, I did a lot of unit testing, removing prior code, etc. I am running PHP 7.0.33. None of the other dozen or so (backup) scripts broke while run by CRON.

Running a cron job manually and immediately, As far as i know there is no way to directly do that as cron has a special purpose - running schedules commands at a specific time. So the best thing is to either to  The cron job specified in /etc/cron.d/0hourly runs the run-parts program once per hour. The run-parts program runs all the scripts located in the /etc/cron.hourly directory. The /etc/cron.hourly directory contains the 0anacron script, which runs the anacron program using the /etdc/anacrontab configuration file shown here.

As nzn indicated this is most likely caused by an error triggered from the included file. From the outside it is hard to diagnose. A likely case is a relative include/require within that file. A way to verify that is by running the script on console from a different location. A f might be to either call cd from cron before starting PHP or doing a chdir(__DIR__) within the primary file before doing further includes.

how can I make cron run a job right now, for testing/debugging , The cron daemon on Linux runs tasks in the background at specific times; it's like the Task Scheduler on Windows. Add tasks to your system's  At this stage, you might have a basic understanding of what is Crontab and how to create and run a cron job in Unix-like systems. Crontab syntax generators. As you can see, scheduling cron jobs is much easier. Also there are few web-based crontab syntax generators available to make this job even easier.

Schedule Tasks with Cron, The cron daemon is a long-running process that executes commands at specific dates and times. You can use this to schedule activities, either  Running a task as cron would is tricky. It requires a modified environment, a non-interactive shell, no attached input terminal, and possibly also a specific shell (e.g. bin/sh instead of /bin/bash). I have made a script that handle all these issues. Run it with your command/script to run as first argument, and you're good to go.

How to Schedule Tasks on Linux: An Introduction to Crontab Files, The commands in the crontab file (and their run times) are checked by the cron daemon, which executes them in the system background. Each  The cron table is the list of tasks scheduled to run at regular time intervals on the system. The daemon which reads the crontab and executes the commands at the right time is called cron. It's named after Kronos, the Greek god of time. This document covers the GNU / Linux version of crontab.

What are cron and crontab, and how do I use them?, Crontab Syntax and Operators #. Each line in the user crontab file contains six fields separated by a space followed by the command to be run. * *  cron or crond is daemon to execute scheduled commands (Vixie Cron) on a Linux or Unix-like systems. Usually, it is started automatically from /etc/init.d or systemd on entering multi-user runlevels.