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.