Tech Recipe – Installing the Technical Analysis PHP PECL Extension

For those of you who have the unenviable task of building a technical analysis library in PHP, Anatoliy Belsky has ported the comprehensive Technical Analysis Library to PHP as a PECL extension. It is a work in progress, and during my trial the pecl extension broke during install. Here’s the bug report  that describes the error in more detail : https://bugs.php.net/bug.php?id=63511. Anatoly has fixed this in the trunk, but a newer, stable release it not out yet.

So until then, here’s how to get it to work properly. The code will work on any Linux machine, but make sure the path to the PECL extension matches your system (see step #4). This was tested on Ubuntu 12.04.

  1. Download and extract the pecl extension
    wget http://pecl.php.net/get/trader-0.3.0.tgz;
    tar xzf trader-0.3.0.tgz;
  2. Edit trader-0.3.0/trader.c, and replace “PHP_FE_END” with “{ NULL, NULL, NULL, 0, 0 }” on line 1225.
    sed -i '1225s/.*/\t{ NULL, NULL, NULL, 0, 0 }/' trader-0.3.0/trader.c
  3. Now compile this PECL extension into a shared library:
    cd trader-0.3.0
    phpize
    ./configure
    make
    sudo make install
  4. Finally, enable the extension in PHP :
    sudo sh -c 'echo "extension=trader.so" > /etc/php5/conf.d/trader.ini'
  5. And check if it’s loaded.
    php -m | grep trader

Here’s the final script in “copy paste” form :

wget http://pecl.php.net/get/trader-0.3.0.tgz;
tar xzf trader-0.3.0.tgz;
sed -i '1225s/.*/\t{ NULL, NULL, NULL, 0, 0 }/' trader-0.3.0/trader.c
cd trader-0.3.0
phpize
./configure
make
sudo make install
sudo sh -c 'echo "extension=trader.so" > /etc/php5/conf.d/trader.ini'
php -m | grep trader

You’ll need PHP 5.3.15 and above for this to install.

Advertisements

2 thoughts on “Tech Recipe – Installing the Technical Analysis PHP PECL Extension

    • If there were no errors during compilation, the module would have loaded into PHP. The last step of the script verifies this. If php -m | grep trader does not show ‘trader’ your module did not load. Also check if it’s loaded in apache with phpinfo().

      That’s my guess.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s