若FreeSWITCH以前已经编译过,需要增加PHP ESL模块支持,操作步骤如下
安装依赖
yum -y install libxml2-devel pcre-devel bzip2-devel curl-devel gmp-devel aspell-devel libtermcap-devel gdbm-devel db4-devel libedit-devel php-devel
进如FreeSWITCH源码目录,执行如下命令
/root/freeswitch-1.4.26
./configure
cd libs/esl/
[root@localhost esl]# make phpmod-install
make MYLIB=".././.libs/libesl.a" SOLINK="-shared -Xlinker -x" CFLAGS="-I/root/freeswitch-1.4.26/libs/esl/src/include -I/root/freeswitch-1.4.26/src/include -I/root/freeswitch-1.4.26/src/include -I/root/freeswitch-1.4.26/libs/libteletone/src -fPIC -fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DHAVE_VISIBILITY=1 -g -ggdb -DHAVE_OPENSSL" CXXFLAGS="-I/root/freeswitch-1.4.26/libs/esl/src/include -I/root/freeswitch-1.4.26/src/include -I/root/freeswitch-1.4.26/src/include -I/root/freeswitch-1.4.26/libs/libteletone/src -fPIC -fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DHAVE_VISIBILITY=1" CXX_CFLAGS="" -C php
make[1]: Entering directory `/root/freeswitch-1.4.26/libs/esl/php'
g++ -I/root/freeswitch-1.4.26/libs/esl/src/include -I/root/freeswitch-1.4.26/src/include -I/root/freeswitch-1.4.26/src/include -I/root/freeswitch-1.4.26/libs/libteletone/src -fPIC -fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DHAVE_VISIBILITY=1 -I/root/freeswitch-1.4.26/libs/esl/src/include -I/root/freeswitch-1.4.26/src/include -I/root/freeswitch-1.4.26/src/include -I/root/freeswitch-1.4.26/libs/libteletone/src -fPIC -fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DHAVE_VISIBILITY=1 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -Wno-unused-label -Wno-unused-function -c esl_wrap.cpp -o esl_wrap.o
g++ -shared -Xlinker -x esl_wrap.o .././.libs/libesl.a -lcrypt -lcrypt -ledit -lncurses -lm -ldl -lnsl -lm -lm -lcrypt -lm -lcrypt -lpthread -o ESL.so -L. -lssl -lcrypto
make[1]: Leaving directory `/root/freeswitch-1.4.26/libs/esl/php'
make -C php install
make[1]: Entering directory `/root/freeswitch-1.4.26/libs/esl/php'
test -d "/usr/lib64/php/modules" || mkdir -p "/usr/lib64/php/modules"
cp ESL.so "/usr/lib64/php/modules"
test -d "/usr/share/pear" || mkdir -p "/usr/share/pear"
cp ESL.php "/usr/share/pear"
test -d "/etc/php.d" || mkdir -p "/etc/php.d"
test -f "/etc/php.d/esl.ini" || echo 'extension=ESL.so' > "/etc/php.d/esl.ini"
make[1]: Leaving directory `/root/freeswitch-1.4.26/libs/esl/php'
到此为止已经编译完成,进入到目录,该目录下有如下文件
cd freeswitch-1.4.26/libs/esl/php/
[root@localhost /]# ls
ESL.php ESL.so esl_wrap.cpp esl_wrap.o Makefile Makefile.am Makefile.in php_ESL.h single_command.php test.php
测试是否成功,可运行single_command.php脚本,传入任何FreeSWITCH命令作为参数,如下已经成功执行命令
[root@localhost /]# ./single_command.php version
Command to run is: version
FreeSWITCH Version 1.4.26~64bit ( 64bit)
后期ESL开发过程中只需拷贝文件ESL.php和ESL.so到项目目录,并引入ESL.php文件即可
参考官方文档https://freeswitch.org/confluence/display/FREESWITCH/Event+Socket+Library