PHP的Erlang扩展安装
由于php的网络通信能力十分棘手,故选择一个强悍的帮手
erlang则是目前这方面的扩展首选,其并发性能、分布式、可维护性、扩展性都是出类拔萃的。
下载地址:http://www.math-hat.com/~zukerma ... rlang-0.0.3.tar.bz2
$ phpize
$ ./configure --enable-erlang
$ make&&make install
可能出现的问题解决:
1、yum install php5-devel(若无)
2、cp erl_interface-3.x.x/include/ei.h 到当前编译目录
3、cp erl_interface-3.x.x/lib/libei.a /usr/local/lib
成功后将modules目录下的erlang.so复制到 php的扩展库目录下,配置php.ini:
extension=erlang.so
erlang.node=node@localhost.localdomain
erlang.cookie=secret
*如何设置node和cookie?
#erl -setcookie secret -name node
*查看node
>node().
*查看cookie
>erlang:get_cookie().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
版主推荐的东西要尝试一下
过些日子谈谈用php+erlang开发强悍的高性能、高可靠、可伸缩、高负载网游的框架
最近几个月一直在win下搞,linux的下有点看不懂了,MARK下
扩展的稳定性尚不知,不过作者相当强了
erlang的扩展本身就比较简单,搞清ei,大不了自己改扩展源码。
erlang是电信级的开发语言,达到9个9的可靠性,基本无敌,otp下非常好用
稳定性好吗
这是官方的帮助信息
http://www.math-hat.com/~zukerman/projects/php-erlang/README
PHP/Erlang 0.0.3
Sat, 02 Feb 2008
Copyright 2008 Itai Zukerman <zukerman@math-hat.com>
INTRODUCTION
PHP/Erlang aims to be a PHP extension with a simple set of functions
for turning a PHP thread into an Erlang C-node. With this extension,
you can shift backend tasks to Erlang, where they belong: caching,
chat, database proxying, everything.
PHP/Erlang is released under the LPGL. See COPYING and COPYING.LESSER
for details.
INSTALLATION
Requirements.
You must have both the PHP and Erlang development headers and
the Erlang ei (and possibly erl_interface) libraries. In Debian
systems these are provided by php5-dev and erlang-dev.
Building.
$ phpize
$ ./configure --enable-erlang
$ make
Installation.
$ cp modules/erlang.so /path/to/php5/modules
Edit php.ini and add:
extension=erlang.so
erlang.node=node@host
erlang.cookie=secret
replacing node@host with your local Erlang node, and erlang.cookie
with the secret cookie for that node.
USAGE
This extension provides these functions:
erlang_init()
Must be called before any other erlang functions. This insures that
we have a (persistent) connection to the node defined in the php.ini.
erlang_self()
Return the PID of the PHP C-node as a resource.
erlang_term( $format, $params )
Build an Erlang term from a format string and an array of params.
The format string specifies the structure of the term with "{", "}",
"[", "|", and "]" chars, and includes values from the params with:
~a atom
~s string
~b binary
~l long
~d double
~p PID
~t an Erlang term
Params are used in the order in which they appear in the format
string. For example:
erlang_term( "{~a,~s}", array( "search", "apples" ) );
erlang_term( "{~a,[~s,~s,~s]}", array( "names", "bob", "joe", "marge" ) );
erlang_term( "{~p,~a,~d}", array( erlang_self(), "sqrt", 153 ) );
erlang_term( "{~a,~t}", array( "item", erlang_term( "{~s}", array( "something" ) ) ) );
erlang_extract( $term )
Take an Erlang term from erlang_receive() or constructed with
erlang_term() and turn it into PHP data. Tuples and lists are
turned into arrays, strings, longs, and doubles into the
corresponding values, and PIDs into PID resources. For example:
erlang_extract( {ok,["a","b"]} ) => array( "ok", array( "a", "b" ) )
erlang_extract( {sqrt,123.4} ) => array( "sqrt", 123.4 )
erlang_receive( [ $timeout ] )
Wait for an Erlang term for up to timeout milliseconds. On timeout
or error, return FALSE. Otherwise return a term to be decoded with
erlang_extract().
erlang_send( $pid, $term [, $timeout ] )
Send a term (probably constructed with erlang_term()) to the PID,
waiting at most timeout milliseconds for success, returning FALSE on
error.
erlang_send_reg( $name, $term [, $timeout ] )
Send a term (probably constructed with erlang_term()) to the
registered name, waiting at most timeout milliseconds for success,
returning FALSE on error.
EXAMPLE
On the Erlang side:
-module( echo ).
-export( [ start/0, echo/0 ] ).
start() ->
register( echo, spawn( ?MODULE, echo, [ ] ) ).
echo() ->
receive
{ Pid, X } ->
Pid ! X,
echo();
quit -> ok
end.
On the PHP side:
erlang_init();
$self = erlang_self();
for( $i = 0; $i < 4; $i++ ) {
$message = erlang_term( "{~p,~s}", array( $self, "foo{$i}" ) );
erlang_send_reg( "echo", $message, 100 );
}
for( $i = 0; $i < 4; $i++ ) {
$message = erlang_receive( 100 );
if( $message !== FALSE ) {
print_r( erlang_extract( $message ) );
} else {
echo( "No message received!n" );
}
}