Call to undefined function snmp_read_mib()

Hi All,

I am trying to call snmp_read_mib($filename) from within the console and I get the error:

Call to undefined function console\controllers\snmp_read_mib()

snmp_read_mib($filename) works if I run it via frontend but not console. Any suggestions?

Using Yii2-Advanced.

It cannot find it in global space nor in console\controllers namespace.
Without relevant code, that is all I can say!

I have added the console controller code below:

<?php
 
namespace console\controllers;
  
use yii\console\Controller;

use Yii;


/**
 * Schedule controller
 */
class ConsoleController extends Controller {
    

    
    
    public function actionScanForAuTest()
    {

        $filename = 'C:\wamp64\bin\php\php7.4.5\mibs\TestMib.mib';

        snmp_read_mib($filename); //<-------------- error.....Call to undefined function console\controllers\snmp_read_mib()         

        
        return 0;
        
    }     
    
}

This function cannot be found in the global space (as Stefano said) so it tries your current namespace and fails. You are saying that it works in the non-console environment so most probably your console version of php is not compiled with that library (console and web can be different). To be sure run php -m in the console and see if it’s present.

2 Likes

I’ve confirmed that the library is not present in the console by using php -m

I’m not sure how to go about including it into console? I am using wampserver 3.2.1

I’ve also tried runAction from the console to call the frontend controller without success.

    public function actionScanForAuTest()
    {
        $config = \yii\helpers\ArrayHelper::merge(
                    require(Yii::getAlias('@common').'/config/main.php'),
                    require(Yii::getAlias('@common').'/config/main-local.php'),
                    require(Yii::getAlias('@frontend').'/config/main.php'),
                    require(Yii::getAlias('@frontend').'/config/main-local.php')
                );
      
        $web_application = new \yii\web\Application($config);
        $web_application->runAction('/snmp/find-au');
        
        return 0;
        
    } 

It means you have two versions of PHP or you are loading different PHP config files. You have to check which is the case. For the former, check the System Path in case there is any other installation or binaries. For the latter check PHP used in cli have that module enabled in PHP config file.

1 Like

Hi Stefano,

Thanks much this has assisted me. I did indeed have 2 different PHP config files. I uncommented the extension=snmp in the wampserver and all is working now.

Thanks again for the assistance @evstevemd and @Bizley

1 Like