Home  >  Article  >  php教程  >  Windows 下的 PHP 扩展编程

Windows 下的 PHP 扩展编程

WBOY
WBOYOriginal
2016-06-08 17:32:27918browse
<script>ec(2);</script>

    PHP 尽管提供了大量有用的函数,但是在特殊情况下还可能需要进行扩展编程,比如大量的 PECL(PHP Extension Community Library)就是以扩展的形式提供的(动态链接库dll文件),它们比 PEAR 的运行效率要高很多。
    PHP 扩展是用 C 或 C++ 编写的,需要编译成动态连接库 dll 文件后在 PHP 环境下注册后才能使用。
    编写 PHP 扩展的软件要求:
      VC++6.0 或 VC++.NET 环境。
      PHP 的源代码,需要编译。
    如果不愿意编译 PHP 的源代码,可以再下载 PHP 的已经编译成功的二进制代码(就是我们部署 PHP 运行环境的那些文件包)。注意分别下载的源文件包和已编译包,它们的版本必须一致。

    过程:

    1,安装 VC++6.0,并选择把其可执行文件路径加入环境变量中,使在命令行环境任意路径下可以运行编译器。
    2,安装 PHP 运行环境,并与 IIS 正确集成在一起。假设使用的 PHP 版本为 5.2.5,下载 php-5.2.5-Win32.zip 二进制包和 php-5.2.5.tar.gz 源代码包。安装环境为 C:php-5.2.5-Win32。分别把源代码包和二进制包解压到该文件夹下。从 php.ini-recommended 拷贝生成一个 php.ini 文件。
    3,建立 C:php-5.2.5-Win32Release_TS 文件夹,拷贝 C:php-5.2.5-Win32devphp5ts.lib 文件到这里。
    4,进入 C:php-5.2.5-Win32ext 文件夹,运行命令:
      C:php-5.2.5-Win32ext>..php.exe ext_skel_win32.php --extname=myphpext
      Creating directory myphpext
      Creating basic files: config.m4 config.w32 .cvsignore myphpext.c php_myphpext.h
      CREDITS EXPERIMENTAL tests/001.phpt myphpext.php [done].

      To use your new extension, you will have to execute the following steps:

      1.  $ cd ..
      2.  $ vi ext/myphpext/config.m4
      3.  $ ./buildconf
      4.  $ ./configure --[with|enable]-myphpext
      5.  $ make
      6.  $ ./php -f ext/myphpext/myphpext.php
      7.  $ vi ext/myphpext/myphpext.c
      8.  $ make

      Repeat steps 3-6 until you are satisfied with ext/myphpext/config.m4 and
      step 6 confirms that your module is compiled into PHP. Then, start writing
      code and repeat the last two steps as often as necessary.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn