Welcome Guest, Not a member yet? Register   Sign In
sapi_windows_vt100_support
#1

(This post was last modified: 01-15-2025, 08:15 AM by okatse.)

Hi
When I try to run the command in the controller, I get this error. Am I doing something wrong, or is it a bug?

PHP Code:
<?php
namespace App\Controllers;
class 
CronController extends BaseController
{
    public function tasks()
    {
      echo  command('start:action cron');
    }


Code:
TypeError
sapi_windows_vt100_support(): Argument #1 ($stream) must be of type resource, string given
SYSTEMPATH\CLI\CLI.php at line 689
Reply
#2

(This post was last modified: 01-15-2025, 12:55 PM by captain-sensible. Edit Reason: the usual suspect )

not exactly sure what your trying to do, or your objective  of running cron from inside CI4 but inside a controller this work ( on linux):

Code:
echo shell_exec("ls");

for anything cron to work on Ci4 you can use cPanel  to set up bash and php to run; so for instance you can clean out logs with a bash script set up from cPanel
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Github  
Reply
#3

According to the documentation, I can call the command anywhere in the code.  https://codeigniter4.github.io/userguide...mands.html
The goal is to execute commands in CodeIgniter 4 (CI4) using crontab
example :


PHP Code:
namespace App\Commands;
use 
CodeIgniter\CLI\BaseCommand;
use 
CodeIgniter\CLI\CLI;
class 
MyTask extends BaseCommand
{
    protected $group      'custom';
    protected $name        'task:mytask';
    protected $description 'This is a custom cron job task.';
    public function run(array $params)
    {
        // Write your logic here
        CLI::write('Executing MyTask command...''green');
    }


PHP Code:
php spark task:mytask 

This example works correctly

But if I want to invoke a command from a controller - and I can because the documentation states that I can.

Code:
<?php

echo command('task:mytask');
I’m getting a SAPI error.
Reply
#4

I don't have windows to check it, but it should work.
What windows/php version are you using?
Reply
#5

(This post was last modified: 01-16-2025, 05:10 AM by okatse.)

Windows 11 , PHP 8.1.6
PHP Code:
<?php
namespace App\Controllers;

use 
CodeIgniter\CLI\CLI;

class 
CronController extends BaseController
{
    public function test()
    {
        echo php_sapi_name();
        
        
if (sapi_windows_vt100_support(STDOUT)) {
            echo "VT100 is supported!\n";
        } else {
            echo "VT100 is not supported.\n";
        }
        command('test:test'); 

Quote:when run from cli php index.php test

I get cliVT100 is supported! and command works ok.
When I run it from the browser http://ci.local/test a get sapi error

Class CLI.php
public static function streamSupports(string $function, $resource): bool

$resource must by @param resource $resource  i got   string(12) "php://output"

For now, I have created a workaround for the problem.

PHP Code:
<?php
namespace App\Controllers;

use 
CodeIgniter\CLI\CLI;

class 
CronController extends BaseController
{
    public function tasksRunningEvery5Minutes()
    {
        Jobs::killUnactive();
        Jobs::startNew();
        Jobs::RemoteCopy();
        Jobs::Stop();

When I run it from the CLI and the browser, it works. But I have opted out of using commands.
Reply
#6

Win 11 Home, PHP 7.4 via XAMPP - no problems.
Reply
#7

(This post was last modified: 01-17-2025, 01:44 PM by okatse.)

How did I check it ?? I ask becouse i get

"Your PHP version must be 8.1 or higher to run CodeIgniter. Current version: 7.4.33"



But I confirm that on another machine and with a different PHP version, it works correctly
Reply
#8

That's an old project with CI 4.3.2.

Seems like your problem is related to the environment.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB