Welcome Guest, Not a member yet? Register   Sign In
CLI gives errors on shared hosting [SOLVED]
#1

(This post was last modified: 06-28-2022, 03:07 PM by pierrick.)

Hi all,
I am attempting to set up a Cron job on a shared host. (PHP 7.4, Apache, MySQL/MariaDb) I have been assured by hosting tech support that the CLI is PHP 7.4.
I'm just trying the basic controller provided in the CI4.2 Documentation (docs/cli/cli_controllers.html):
Code:
<?php

namespace App\Controllers;

use CodeIgniter\Controller;

class Tools extends Controller
{
    public function message($to = 'World')
    {
        return "Hello {$to}!" . PHP_EOL;
    }
}

I have added the route:
Code:
$routes->cli('tools/message/(:segment)', 'Tools::message/$1');

I've set up the Cron job via the cPanel interface provided by the hosting people. Other Cron jobs for another app using CI3 work fine by the way.
And here's the error I get in the CI4 logs:
Code:
CRITICAL - 2022-06-24 12:56:01 --> array_shift() expects parameter 1 to be array, null given in SYSTEMPATH/HTTP/CLIRequest.php on line 181.
1 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'array_shift() expects parameter 1 to be array, null given', 'SYSTEMPATH/HTTP/CLIRequest.php', 181, [...])
2 SYSTEMPATH/HTTP/CLIRequest.php(181): array_shift(null)
3 SYSTEMPATH/HTTP/CLIRequest.php(72): CodeIgniter\HTTP\CLIRequest->parseCommand()
4 SYSTEMPATH/Config/Services.php(129): CodeIgniter\HTTP\CLIRequest->__construct(Object(Config\App))
5 SYSTEMPATH/Config/BaseService.php(251): CodeIgniter\Config\Services::clirequest(Object(Config\App), false)
6 SYSTEMPATH/Config/BaseService.php(192): CodeIgniter\Config\BaseService::__callStatic('clirequest', [...])
7 SYSTEMPATH/Config/Services.php(124): CodeIgniter\Config\BaseService::getSharedInstance('clirequest', Object(Config\App))
8 SYSTEMPATH/Config/BaseService.php(251): CodeIgniter\Config\Services::clirequest(Object(Config\App))
9 SYSTEMPATH/CodeIgniter.php(599): CodeIgniter\Config\BaseService::__callStatic('clirequest', [...])
10 SYSTEMPATH/CodeIgniter.php(315): CodeIgniter\CodeIgniter->getRequestObject()
11 FCPATH/index.php(55): CodeIgniter\CodeIgniter->run()

The shared server access log also gives me the following:
Code:
[24-Jun-2022 14:33:02 Pacific/Auckland] PHP Fatal error:  Uncaught ErrorException: Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in /home/<server name>/apps/system/CLI/CLI.php:159
Stack trace:
#0 /home/<server name>/apps/system/CLI/CLI.php(159): CodeIgniter\Debug\Exceptions->errorHandler(2, 'Use of undefine...', '/home/zclmanco4...', 159, Array)
#1 /home/<server name>/apps/system/CLI/CLI.php(1018): CodeIgniter\CLI\CLI::init()
#2 /home/<server name>/apps/system/Autoloader/Autoloader.php(284): include_once('/home/zclmanco4...')
#3 /home/<server name>/apps/system/Autoloader/Autoloader.php(261): CodeIgniter\Autoloader\Autoloader->includeFile('/home/zclmanco4...')
#4 /home/<server name>/apps/system/Autoloader/Autoloader.php(239): CodeIgniter\Autoloader\Autoloader->loadInNamespace('CodeIgniter\\CLI...')
#5 [internal function]: CodeIgniter\Autoloader\Autoloader->loadClass('CodeIgniter\\CLI...')
#6 /home/<server name>/apps/clman/app/Views/errors/cli/error_exception.php(6): spl_autoload_call('CodeIgnit in /home/<server name>/apps/system/CLI/CLI.php on line 159

Note: I redacted the actual server name.

I saw a thread on the forum mentioning the "undefined constant STDOUT" error. It gave a 'fix' which involved hacking into the CLI.php system file and add some constants definitions. Naturally, I am skeptical of any fix involving the modification of system files...
That said, I tried it but the error remains. I subsequently reverted to the original CLI.php

Any help would be greatly appreciated.
Thanks in advance.
Reply
#2

Can you show the cron definition?

And can you get the values of PHP_SAPI and $_SERVER?
Reply
#3

(06-23-2022, 08:55 PM)kenjis Wrote: Can you show the cron definition?

And can you get the values of PHP_SAPI and $_SERVER?

Hi kenjiis,

Thanks for the reply.

Here's the Cron command:
Code:
php -q /home/<server name>/subdomains/cm.clman.co.nz/index.php tools

The script fails completely so I'm not sure how I can get responses to either php_sapi_name() or a var dump of $_server. Any clues on how I can do that please?
Thanks.
Reply
#4

Hi all,

Digging around a bit more I discovered that php needs to be called by its full path (unlike my development machine.)
Not:
Code:
php -q /home/...

But instead:
Code:
/usr/local/bin/php -q /home/...

And it's all working.
Thank you all.
Reply
#5

Please edit your topic title and add to the end [SOLVED]
Thank you.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(06-27-2022, 12:07 AM)InsiteFX Wrote: Please edit your topic title and add to the end [SOLVED]
Thank you.

Done.  Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB