Search code examples
phpsymfonypearpecl

How to use PECL extension from inside of framework


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 .