I need to use a third party library written in C from PHP, preferably as a shared extension.
C library I'm referring to is Tulip Indicators:
- Documentation: https://tulipindicators.org/usage
- GitHub: https://github.com/TulipCharts/tulipindicators
every method in the library has the same exact signature.
Target PHP version: >= 7.2.0What I have achieved so far
I tried doing it by using SWIG 3.0 (http://www.swig.org/Doc3.0/SWIGDocumentation.html).
While compiling and linking the library I had to include -fPIC flag to each step, I will indicate the involved steps here for reference:
- Add -fPIC as the first CCFLAGS in the library's Makefile
- gcc -fPIC `php-config --includes` -c tulip_indicators_wrap.c indicators.h
- gcc -fPIC -shared tulip_indicators_wrap.o libindicators.a -o tulip_indicators_php_wrap.so
I tried implementing some array helpers in SWIG interface file that works for simpler cases, but without succeding in this case.Note:
SWIG usage is not mandatory.What I need
A step by step guide on how to achieve my need, together with a simple PHP script that will work as an example.
Said script has to succesfully compute only one indicator: the Stochastic Oscillator (https://tulipindicators.org/stoch), being it the most complete one.
Inputs, options and expected outputs can be found in the same page of the indicator's description.Note:
performance is a priority: adopt the most efficient solution and avoid every possible memory leak.