Home Backend Development PHP Tutorial windows下配置php5.5开发环境及开发扩展_php技巧

windows下配置php5.5开发环境及开发扩展_php技巧

May 16, 2016 pm 08:27 PM
windows development environment

网上的教程是比较多的,但是我发现在windows下的扩展开发比较少,而且大多都是php5.3版本以前的,今天我就给大家讲解一下php扩展开发,我就拿php5.5的版本来说明一下的了

windows环境(我个人的)

复制代码 代码如下:

windows 8.1 企业版(mac os Boot Camp安装的)
Visual Studio 2012 版本
msysgit  (http://msysgit.github.io/ 下载)
php-sdk-binary-tools-20110915.zip (http://windows.php.net/downloads/php-sdk/下载)
deps-5.5-vc11-x86.7z                  (http://windows.php.net/downloads/php-sdk/下载)
php-5.5.20                        (http://php.net/downloads.php下载,这个版本不定自己选择)

第一步
解压php-sdk-binary-tools的二进制包,譬如我解压到我的C:\php-sdk文件夹中,现在的目录结构如下

复制代码 代码如下:

C:\php-sdk
    --bin
    --script
    --share

然后,这个是你已经安装完成了visual studio 2012,打开VS2012 Native Tools Command Prompt命令行工具

复制代码 代码如下:

#进入目录
cd C:\php-sdk
#设置环境变量
bin\phpsdk_setvars.bat
#创建常用的php-sdk目录
bin\phpsdk_buildtree.bat phpdev

如果我们打开bin\phpsdk_buildtree.bat文件就会发现它只创建到VC9,没有VC11,但是我们如果开发php5.5版本,我们需要的是VC11,这时候我们就要把C:\php-sdk\phpdev\vc9复制一份到C:\php-sdk\phpdev\vc11,现在的目录结构如下:

复制代码 代码如下:

C:\php-sdk\phpdev\
                --vc6
                --vc8
                --vc9
                --vc11

因为我下载的deps-5.5-vc11-x86.7z,所以我要解压deps-5.5-vc11-x86.7z到C:\php-sdk\phpdev\vc11\x86\deps文件夹下覆盖,里边都是我们需要的库文件和一些必要的工具等等。
然后,将我们下载的php-5.5.20.tar.bz2解压到C:\php-sdk\phpdev\vc11\x86\php-5.5.20文件夹中。

编译安装php

回到VS2012 Native Tools Command Prompt
#进入php源目录文件夹
cd c:\php-sdk\phpdev\vc11\x86\php-5.5.20
buildconf
#查看带的扩展和编译命令
configure --help
php-sdk

如果你没有安装php,现在这里就帮助到你了,可以先编译安装一下php
configure --disable-all --enable-cli
然后,你会看到Type 'nmake' to build PHP,然后编译
nmake
在C:\php-sdk\phpdev\vc11\x86\php-5.5.20\Release_TS文件夹下就生成了php.exe文件,环境变量中加入这个路径,好在命令行中能使用php命令。

开发PHP的第一个扩展

假如我们要开发一个widuu()函数,实现的效果如下

复制代码 代码如下:

function widuu($string){
    return "your first extension {$string} is ok";
}

进入扩展目录,生成扩展文件夹

复制代码 代码如下:

cd C:\php-sdk\phpdev\vc11\x86\php-5.5.20\ext
#输入php ext_skel_win32.php --extname=扩展名称
php ext_skel_win32.php --extname=widuuweb

这时候我们在C:\php-sdk\phpdev\vc11\x86\php-5.5.20\ext就看到了自己的目录widuuweb,打开widuuweb\php_widuuweb.h,在
#PHP_MINFO_FUNCTION(widuuweb);下一行写入自己的函数,譬如我定义的是widuu()函数
PHP_FUNCTION(widuu);
打开php_widuuweb.c编写函数,在PHP_FUNCTION(confirm_widuuweb_compiled)下

复制代码 代码如下:

PHP_FUNCTION(widuu){
    char *arg_string = NULL;
    int  arg_len,str_len;
    char *string;
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s",&arg_string,&arg_len) == FAILURE){
        return;
    }
    str_len = spprintf(&string,0,"your first extension %.78s is ok",arg_string);
    RETURN_STRINGL(string,str_len,0);
}

然后找到PHP_FE(confirm_widuuweb_compiled, NULL),在下边注册你的函数

复制代码 代码如下:

const zend_function_entry widuuweb_functions[] = {
    PHP_FE(confirm_widuuweb_compiled,   NULL)       /* For testing, remove later. */
    PHP_FE(widuu,NULL)
    PHP_FE_END  /* Must be the last line in widuuweb_functions[] */
};

修改C:\php-sdk\phpdev\vc11\x86\php-5.5.20\ext\widuuweb\config.w32,去掉
// ARG_ENABLE("widuuweb", "enable widuuweb support", "no");
前边的注释,vs命令行,输入cd .. 到php-5.5.20目录中,输入下面的命令
buildconf --force
#查看扩展
configure --help
如果,有错误,大家可以打开,目录下configure.js查看,我这个出现了错误,是configure.js的4791行,
ARG_ENABLE("widuuweb", "enable widuuweb support", "no");  */
多了一个*/的注释,去掉就可以了,然后再输入
configure --help
就看到了,有一行
 --enable-widuuweb             enable widuuweb support
然后配置
configure --disable-all --enable-cli --enable-widuuweb=shared
php动态扩展

其中--enable-widuuweb=shared动态扩展,正好与静态扩展相对。
然后输入nmake,完成后,我们在C:\php-sdk\phpdev\vc11\x86\php-5.5.20\Release_TS目录下就发现了php_widuuweb.dll文件,可以放到环境中测试了。
如果你本地没有安装php环境,而是跟我一样只是编译了php,如果测试,我建议静态编译看效果
configure --disable-all --enable-cli --enable-widuuweb=static
nmake
然后,你可以再Release_TS目录下,输入
php -r "echo widuu('widuu');"  //输出"your first extension widuu is ok"
ok,就说到这里,以后再慢慢来讲,有什么不懂的大家可以留言,基础的ZEND_API,大家可以去walu.cc查看

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Four ways to implement multithreading in C language Four ways to implement multithreading in C language Apr 03, 2025 pm 03:00 PM

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

How to avoid third-party interfaces returning 403 errors in Node environment? How to avoid third-party interfaces returning 403 errors in Node environment? Apr 01, 2025 pm 02:03 PM

How to avoid the third-party interface returning 403 error in the Node environment. When calling the third-party website interface using Node.js, you sometimes encounter the problem of returning 403 error. �...

Where to download Python .whl files under Windows? Where to download Python .whl files under Windows? Apr 01, 2025 pm 08:18 PM

Python binary library (.whl) download method explores the difficulties many Python developers encounter when installing certain libraries on Windows systems. A common solution...

How to efficiently read Windows system logs and get only information from the last few days? How to efficiently read Windows system logs and get only information from the last few days? Apr 01, 2025 pm 11:21 PM

Efficient reading of Windows system logs: Reversely traverse Evtx files When using Python to process Windows system log files (.evtx), direct reading will be from the earliest...

How to speed up the loading speed of PS? How to speed up the loading speed of PS? Apr 06, 2025 pm 06:27 PM

Solving the problem of slow Photoshop startup requires a multi-pronged approach, including: upgrading hardware (memory, solid-state drive, CPU); uninstalling outdated or incompatible plug-ins; cleaning up system garbage and excessive background programs regularly; closing irrelevant programs with caution; avoiding opening a large number of files during startup.

Why can't my code get the data returned by the API? How to solve this problem? Why can't my code get the data returned by the API? How to solve this problem? Apr 01, 2025 pm 08:09 PM

Why can't my code get the data returned by the API? In programming, we often encounter the problem of returning null values ​​when API calls, which is not only confusing...

c What are the differences between the three implementation methods of multithreading c What are the differences between the three implementation methods of multithreading Apr 03, 2025 pm 03:03 PM

Multithreading is an important technology in computer programming and is used to improve program execution efficiency. In the C language, there are many ways to implement multithreading, including thread libraries, POSIX threads, and Windows API.

See all articles