免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6628 | 回复: 6
打印 上一主题 下一主题

[其他] PHP的Erlang扩展安装 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-05 09:23 |只看该作者 |倒序浏览
由于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().

论坛徽章:
0
2 [报告]
发表于 2009-11-05 11:25 |只看该作者
这是官方的帮助信息

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" );
        }
    }

论坛徽章:
0
3 [报告]
发表于 2009-11-05 11:37 |只看该作者
稳定性好吗

论坛徽章:
0
4 [报告]
发表于 2009-11-05 11:49 |只看该作者
扩展的稳定性尚不知,不过作者相当强了

erlang的扩展本身就比较简单,搞清ei,大不了自己改扩展源码。


erlang是电信级的开发语言,达到9个9的可靠性,基本无敌,otp下非常好用

论坛徽章:
0
5 [报告]
发表于 2009-11-05 22:41 |只看该作者
最近几个月一直在win下搞,linux的下有点看不懂了,MARK下

论坛徽章:
0
6 [报告]
发表于 2009-11-10 12:51 |只看该作者
过些日子谈谈用php+erlang开发强悍的高性能、高可靠、可伸缩、高负载网游的框架  

论坛徽章:
0
7 [报告]
发表于 2009-11-17 14:25 |只看该作者
版主推荐的东西要尝试一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP