Tuesday, August 30, 2022

[FIXED] How to use PECL extension from inside of framework

Issue

I am using PECL extension trader

It works inside the ./src/MyBundle/Command/MyCommand.php without any installtion or include.

function calcByCode()
    \trader_ma($array, 5, TRADER_MA_TYPE_EMA);
}

however inside the Controller

./src/MyBundle/Controller/MyController.php

public function indexAction()
{
    \trader_ma($array, 5, TRADER_MA_TYPE_EMA); 
    //(or trader_ma($array, 5, TRADER_MA_TYPE_EMA);)

    return $this->render('AcmeTopBundle:Default:index.html.twig');
}

returns error like this

Fatal error: Call to undefined function TopBundle\MyController\trader_ma()

How can I use PECL extension inside the condroller of Symfony2 framework??


Solution

It's mostly a case of the extension not being installed correctly. To know if the extension if installed correctly or not, make use of phpinfo for both cli and web ( cgi / fpm ).

There is a chance that the extension is enabled only in the php.ini for PHP CLI and not for fpm / cgi ( web server ) . So make sure you enable the trader module in the appropriate php.ini file .



Answered By - Vamsi Krishna B
Answer Checked By - Katrina (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.