当前位置:首页 > PHP教程 > PHP高级教程

扩展你的 PHP 之入门篇

扩展你的php

  • 扩展你的php
  • 扩展的3种方式
  • extension dll方式的扩展
  • 小结
  •   首先注意,以下所有的一切皆在 win 下进行,使用的工具的 vc++6.0。

    扩展你的php
      php以方便快速的风格迅速在web系统开发中占有了重要地位. php本身提供了丰富的大量的函数及功能. 长话短说. 我们看看我们如何进行扩展.

    扩展的3种方式

    • external modules
    • built-in modules
    • the zend engine

    3 种方式的优缺点可参见 php 手册:http://www.php.net/manual/en/zend.possibilities.php

    extension dll

    1、首先我们去下个 php 的 source. 可以看到有以下几个重要的目录。ext,main,tsrm,zend,另外我们可能还需要 bindlib_w32(需要你从 cvs 上下),及 php 目录下的 php4ts.lib。

    2、打开 vc,新建一个 win32 dynamic-link library,如下图:

    3、点 ok,选择“an empty dll project”,点击完成。

    4、设置 build 的 active configuration,选 release:)

    5、project->settings

    预定义标识. 整个如下:

    zend_debug=0, compile_dl_binzy, zts=1, zend_win32, php_win32, have_binzy=1

    这个是包含路径,上面所提及的几个路径都可以加入。

    选择 multithreaded dll。

    取名时随便的,要 link php4ts.lib~~  
    o,忘了,别忘了加上 /tc 的参数:

    6、写代码.

      建个头,建个身体。
    binzy.h

    // binzy wu
    // 2004-4-9
    // php extension

    #if have_binzy
    extern zend_module_entry binzy_module_entry;
    #define binzy_module_ptr &binzy_module_entry

    php_function(hellobinzy); //
    php_minfo_function(binzy); //
    #endif

    binzy.c

    // binzy wu
    // 2004-4-9
    // php extension

    #include "php.h"
    #include "binzy.h"

    #if have_binzy

    #if compile_dl_binzy
    zend_get_module(binzy)
    #endif

    function_entry binzy_functions[] = {
        php_fe(hellobinzy, null)
        {null, null, null}
    };

    zend_module_entry binzy_module_entry = {
        standard_module_header,
        "binzy", binzy_functions, null, null, null, null, php_minfo(binzy), no_version_yet, standard_module_properties
    };

    php_minfo_function(binzy)
    {
        php_info_print_table_start();
        php_info_print_table_row(2, "binzy extension", "enable");
        php_info_print_table_end();
    }

    php_function(hellobinzy)
    {
        zend_printf("hello binzy");
    }

    #endif

    7、编译,修改 php.ini,restart apache,写个 php

    <?php
        hellobinzy();
    ?>

    hoho~~~

    phpinfo();

    小结
      这算入门篇, 以后再一步步来~~. 慢慢深入, 有些我也不了解的。 偶是初学者。



    【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!