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.