Page 1 of 1
CMSCLI can only be invoked from command line
Posted: Sat Mar 23, 2019 9:48 pm
by rotezecke
I want to use CMSCLI as a cronjob. My line of code works fine from command line, but when set as cronjob (via cpanel) i get
The application may only be invoked from a command line, got "cgi-fcgi"
What am I doing wrong.
Code: Select all
/path/to/cmscli.phar -d /path/to/cmsms cache-clear
Re: CMSCLI can only be invoked from command line
Posted: Sun Mar 24, 2019 2:26 am
by rotezecke
Full disclosure: i forgot about my modified config.php file where I have an is_cli function, testing whether a webserver or CLI is accessing CMSMS. cmscli should fail with the first test and go to the else statement (it does so when executing from command line, but not from crontab.
Code: Select all
function is_cli()
{
if ( defined('STDIN') )
{
return true;
}
if ( php_sapi_name() === 'cli' )
{
return true;
}
if ( array_key_exists('SHELL', $_ENV) ) {
return true;
}
if ( empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0)
{
return true;
}
if ( !array_key_exists('REQUEST_METHOD', $_SERVER) )
{
return true;
}
return false;
}
if(!is_cli() && (strpos($_SERVER['SERVER_ADDR'],'10.10.10.',0) === 0 || $_SERVER['SERVER_NAME'] =='xxxxx')) {
//wrong config
} else {
//correct config
}
Re: CMSCLI can only be invoked from command line
Posted: Sun Mar 24, 2019 3:09 pm
by deactivated010521
I don't see the reason why you have modified your config.php file.
When running cmscli as crontab be sure to specify where cmscli is installed (full_cmscli_path) Also point to to the cmsms root directory. (~ cmscli -d full_cmsms_root_path).
php-cli is the executer based on your system the path can be `/usr/bin/php` || `/bin/php` (~ whereis php).
Code: Select all
# clear cmsms cache every 5 minutes
*/5 * * * * /usr/bin/php /full_cmscli_path/cmscli -d /full_cmsms_root_path/public cache-clear 2>&1
double check that you have set excution permissions on cmscli (eg. ~ chmod 755 cmscli).
Re: CMSCLI can only be invoked from command line
Posted: Sun Mar 24, 2019 3:47 pm
by calguy1000
Your function is incorrect.
by default cron is not run from a console/terminal/tty. Therefore there would be no open STDIN resource in PHP. Unless perhaps you are piping data into a command.
Re: CMSCLI can only be invoked from command line
Posted: Sun Mar 24, 2019 10:32 pm
by rotezecke
I just replace my config file with the original one, no difference. Cron Daemon sends me this email:
Content-type: text/html; charset=UTF-8
The application may only be invoked from a command line, got "cgi-fcgi"
I tried all sorts of ways to call cmscli: absolute path, relative, ~, cd to directory, as one-liner, or inside a script.sh (with execute permissions). When my call to cmscli was incorrect, cron sent a different error message.
Re: CMSCLI can only be invoked from command line
Posted: Mon Mar 25, 2019 10:54 am
by velden
Are you using the method like Arnoud described? Calling the php executable from cron explicitly.
*/5 * * * * /usr/bin/php /full_cmscli_path/cmscli -d /full_cmsms_root_path/public cache-clear 2>&1
Further I note that you're using cmscli.phar while reading the install instructions (
viewtopic.php?f=1&t=77184) it should have been renamed to cmscli (not sure that's relevant).
Re: CMSCLI can only be invoked from command line
Posted: Mon Mar 25, 2019 3:42 pm
by rotezecke
I have about 10 other cronjobs, all using /usr/bin/php -q, working fine.
/usr/bin/php /home/xxx/bin/cmscli -d /home/xxx/public_html cache-clear 2>&1
Renaming cmscli.phar to cmscli, and even with 777 permissions made no difference.
This is on a shared host with PHP 7.2.16, Linux 2.6.32-896.16.1.lve1.4.54.el6.x86_64, CMSMS 2.2.10.
Re: CMSCLI can only be invoked from command line
Posted: Mon Mar 25, 2019 4:00 pm
by velden
Out of curiosity I created a cronjob and seems to work well. That means: I receive an email containing the cronjob result:
Cache will be cleared on the next request
Code: Select all
/usr/local/bin/php /home/xxx/yyy.nl/cmscli -d /home/xxx/yyy.nl/ cache-clear
Re: CMSCLI can only be invoked from command line
Posted: Mon Mar 25, 2019 4:02 pm
by rotezecke
i figured it out: i need to call php-cli explicitly with cmscli.
Code: Select all
/usr/bin/php-cli /home/xxx/bin/cmscli -d /home/xxx/public_html cache-clear
Thanks everyone.