Setting up cron job


#1

I'm trying to set up the cron job using cPanel's Cron Jobs tab. I set up the job to run every fifteen minutes, and use the command 'php -f /path/to/cron.php'.

This ran twice fine, but then each time afterwards it fails with an error, {"data":{"message":"Backgroundjobs are using system cron!"},"status":"error"}.

What does "Backgroundjobs are using system cron!" signify?


#2

This happens in cases where we cannot detect that the php script is executed from command line.

Please run this as cron:

$ php -r "echo php_sapi_name(). PHP_EOL;"


#3

I ran that string exactly as it appears, with the following result.

Error in argument 1, char 2: option not found r
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
      php <file> [args...]
 -a               Run interactively
 -b <address:port>|<port> Bind Path for external FASTCGI Server mode
 -C               Do not chdir to the script's directory
 -c <path>|<file> Look for php.ini file in this directory
 -n               No php.ini file will be used
 -d foo[=bar]     Define INI entry foo with value 'bar'
 -e               Generate extended information for debugger/profiler
 -f <file>        Parse <file>.  Implies `-q'
 -h               This help
 -i               PHP information
 -l               Syntax check only (lint)
 -m               Show compiled in modules
 -q               Quiet-mode.  Suppress HTTP Header output.
 -s               Display colour syntax highlighted source.
 -v               Version number
 -w               Display source with stripped comments and whitespace.
 -z <file>        Load Zend extension <file>.
 -T <count>       Measure execution time of script repeated <count> times.


#4

can you please run php --version? THX


#5
PHP 5.6.24 (cgi-fcgi) (built: Jul 29 2016 12:54:16)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
   with the ionCube PHP Loader v4.7.5, Copyright (c) 2002-2014, by ionCube Ltd., and
   with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
   with Suhosin v0.9.38, Copyright (c) 2007-2015, by SektionEins GmbH

#6

maybe you are using a different php? see http://stackoverflow.com/questions/10886539/why-does-php-sapi-not-equal-cli-when-called-from-a-cron-job

Sorry - just wild guessing here ....


#7

Hi,

moving to the miscellaneous category as this is clearly no issue in ownCloud but rather an environmental misconfiguration where the php binary is not providing the expected php-cli SAPI but still the webserver environment as seen in the php --version output:

@Pazu Please contact the support of your hoster (or maybe also a CPanel support) and ask them for the binary which shows this one when running php --version:

(cli)

This one needs to be used and the cronjob is then running without an issue.


#8

Just had a short search on google and on CPanel it looks like the binary is named php-cli rather then your used php:


#9

Thanks, @RealRancor. Running php-cli rather than php gave the following results.

PHP 5.6.24 (cli) (built: Jul 29 2016 12:53:35)

Thus, it seems my command needs to be 'php-cli -f /path/to/cron.php' rather than 'php -f /path/to/cron.php'.


#10

Hi,

yes that should do the trick here. :slight_smile:


#11

Indeed, it appears to work great. Thanks @RealRancor and @DeepDiver1975!

Is this perhaps something which ought to get added to the docs?


#12

Its already there:

On some systems it might be required to call php-cli instead of php.

https://doc.owncloud.org/server/latest/admin_manual/configuration_server/background_jobs_configuration.html#cron


#13

when the cron job string is set to ‘php’
i get the ‘backgroundjobs are using system cron’ error, but the web interface reports that cron IS working normally.
when the cron job is set to ‘php-cli’
i get the ‘no such file or directory’ error, and web interface does not register a successful cron operation.
when the cron job is set to ‘ea-php72’
i get an error page of ‘internal server error’, and web interface does not register a successful cron operation.

my webserver is set to php72, and php 72 is reflected in the generated config report from the admin page.

cron is listed as the preferred method in documentation, and everything has been working fine since 10.0.3, while seeming that everything is working correctly now in 10.0.9.5 - except for the ‘backgroundjobs are using system cron’ error.

other than saying that the ‘backgroundjobs are using system cron’ error has to be fixed, there is no documentation on what can fail when that error is present, or what to do when the error is there WHILE the web interface says that cron is working.

please advise. there does not seem to be any recent discussion online about the ‘backgroundjobs are using system cron’ error.


#14

found my 3 issues. fwiw, i’m hosted at inmotion. hope this helps someone else.
i had began on shared hosting via softaculous installer. I was migrated to VPS hosting.
1.the php mismatch @DeepDiver1975 mentioned was present, so i changed to ‘ea-php72’ instead of ‘php’ (setting may be specific to inmotion).
2.the cron was originally setup with the switch of ‘-q’, the documentation now calls for ‘-f’, not sure what impact this had.
3.the cron started as ‘/usr/bin/php…’ when installed on the shared hosting account. when the account was migrated to vps, the cron did not get edited to start with ‘/usr/local/bin/php…’ as it should have.

strangely enough, when the cron was ‘/usr/bin/php…’ the web interface admin page of owncloud reported successful cron activity, and the installation seemed to work just fine. perhaps now that i stumbled across this error that was going to a hidden email account in my cpanel, my installation might run faster now that things are fixed.

as to what fails when the web interface says cron is working but the “backgroundjobs are using system cron” error is present: test emails send, but activity emails do not. files delete via the web interface, but storage space is not reallocated for use. after the fix, gained almost 6GB of reported free space, and started receiving activity emails.