Although PHP provides a large number of useful functions, extension programming may be required under special circumstances. For example, a large number of PECL (PHP Extension Community Library) are provided in the form of extensions (dynamic link library dll files ), they run much more efficiently than PEAR.
PHP extension is written in C or C and needs to be compiled into a dynamic link library dll file and registered in the PHP environment before it can be used.
Software requirements for writing PHP extensions:
VC 6.0 or VC .NET environment.
The source code of PHP needs to be compiled.
If you are not willing to compile the source code of PHP, you can download the successfully compiled binary code of PHP (that is, the file packages we use to deploy the PHP runtime environment). Note that the versions of the source file package and compiled package downloaded separately must be consistent.
Process:
1. Install VC 6.0 and choose to add its executable file path to the environment variable so that the compiler can be run in any path in the command line environment.
2. Install the PHP running environment and correctly integrate it with IIS. Assuming that the PHP version used is 5.2.5, download the php-5.2.5-Win32.zip binary package and php-5.2.5.tar.gz source code package. The installation environment is C:php-5.2.5-Win32. Extract the source code package and binary package to this folder respectively. Generate a php.ini file from php.ini-recommended copy.
3. Create the C:php-5.2.5-Win32Release_TS folder and copy the C:php-5.2.5-Win32devphp5ts.lib file here.
4. Enter the C:php-5.2.5-Win32ext folder and run the command:
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.
As a result, a folder myphpext is generated under ext, which contains a PHP extension application programming framework. myphpext can be named arbitrarily. The format of the dll file generated in the future is php_[extname].dll. What we generate is php_myphpext.dll. The prompt information 1.2...8 of the running results is mainly for the Linux/Unix environment, and we do not need to pay attention to it. In fact, the config.m4 file may also need to be modified under Windows, but it is not needed for our simple framework yet.
The folder myphpext contains several files, including:
myphpext.dsp is the project file and will be used later;
Myphpext.php extension test file;
php_myphpext.h extended function definition header file
Myphpext.c extension function specific implementation
The above 2 important file contents:
php_myphpext.h file:
/*
----------------------------------------------------------------------
| PHP Version 5 |
----------------------------------------------------------------------
| Copyright (c) 1997-2007 The PHP Group |
----------------------------------------------------------------------
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
----------------------------------------------------------------------
| Author: |
----------------------------------------------------------------------
*/
/* $Id: header,v 1.16.2.1.2.1 2007/01/01 19:32:09 iliaa Exp $ */
#ifndef PHP_MYPHPEXT_H
#define PHP_MYPHPEXT_H
extern zend_module_entry myphpext_module_entry;
#define phpext_myphpext_ptr &myphpext_module_entry
#ifdef PHP_WIN32
#define PHP_MYPHPEXT_API __declspec(dllexport)
#else
#define PHP_MYPHPEXT_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(myphpext);
PHP_MSHUTDOWN_FUNCTION(myphpext);
PHP_RINIT_FUNCTION(myphpext);
PHP_RSHUTDOWN_FUNCTION(myphpext);
PHP_MINFO_FUNCTION(myphpext);
PHP_FUNCTION(confirm_myphpext_compiled); /* For testing, remove later. */
PHP_FUNCTION(HelloPHP);
/*
Declare any global variables you may need between the BEGIN
and END macros here:
ZEND_BEGIN_MODULE_GLOBALS(myphpext)
long global_value;
char *global_string;
ZEND_END_MODULE_GLOBALS(myphpext)
*/
/* In every utility function you add that needs to use variables
in php_myphpext_globals, call TSRMLS_FETCH(); after declaring other
variables used by that function, or better yet, pass in TSRMLS_CC
after the last function argument and declare your utility function
with TSRMLS_DC after the last declared argument. Always refer to
the globals in your function as MYPHPEXT_G(variable). You are
encouraged to rename these macros something shorter, see
examples in any other php module directory.
*/
#ifdef ZTS
#define MYPHPEXT_G(v) TSRMG(myphpext_globals_id, zend_myphpext_globals *, v)
#else
#define MYPHPEXT_G(v) (myphpext_globals.v)
#endif
#endif /* PHP_MYPHPEXT_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim
*/
/*
----------------------------------------------------------------------
| PHP Version 5 |
----------------------------------------------------------------------
| Copyright (c) 1997-2007 The PHP Group |
----------------------------------------------------------------------
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
----------------------------------------------------------------------
| Author: |
----------------------------------------------------------------------
*/
/* $Id: header,v 1.16.2.1.2.1 2007/01/01 19:32:09 iliaa Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_myphpext.h"
/* If you declare any globals in php_myphpext.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(myphpext)
*/
/* True global resources - no need for thread safety here */
static int le_myphpext;
/* {{{ myphpext_functions[]
*
* Every user visible function must have an entry in myphpext_functions[].
*/
zend_function_entry myphpext_functions[] = {
PHP_FE(confirm_myphpext_compiled, NULL) /* For testing, remove later. */
PHP_FE(HelloPHP, NULL)
{NULL, NULL, NULL} /* Must be the last line in myphpext_functions[] */
};
/* }}} */
/* {{{ myphpext_module_entry
*/
zend_module_entry myphpext_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"myphpext",
myphpext_functions,
PHP_MINIT(myphpext),
PHP_MSHUTDOWN(myphpext),
PHP_RINIT(myphpext), /* Replace with NULL if there's nothing to do at request start */
PHP_RSHUTDOWN(myphpext), /* Replace with NULL if there's nothing to do at request end */
PHP_MINFO(myphpext),
#if ZEND_MODULE_API_NO >= 20010901
"0.1", /* Replace with version number for your extension */
#endif
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_MYPHPEXT
ZEND_GET_MODULE(myphpext)
#endif
/* {{{ PHP_INI
*/
/* Remove comments and fill if you need to have entries in php.ini
PHP_INI_BEGIN()
PHP_INI_END()
*/
/* }}} */
/* {{{ php_myphpext_init_globals
*/
/* Uncomment this function if you have INI entries
static void php_myphpext_init_globals(zend_myphpext_globals *myphpext_globals)
{
myphpext_globals->global_value = 0;
myphpext_globals->global_string = NULL;
}
*/
/* }}} */
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(myphpext)
{
/* If you have INI entries, uncomment these lines
REGISTER_INI_ENTRIES();
*/
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(myphpext)
{

查看phpinfo()函数输出、使用命令行工具和检查PHP配置文件均可以查看php用了哪些扩展。1、查看phpinfo()函数输出,创建一个简单的PHP脚本,将这个脚本保存为phpinfo.php,并将其上传到您的Web服务器,在浏览器中访问此文件,使用浏览器的搜索功能,在页面中查找关键字"extension"或"extension_loaded",以找到有关扩展的信息即可。

如何使用PHP扩展PDO连接Oracle数据库导语:PHP是一种非常流行的服务器端编程语言,而Oracle是一款常用的关系型数据库管理系统。本文将介绍如何使用PHP扩展PDO(PHPDataObjects)来连接Oracle数据库。一、安装PDO_OCI扩展要连接Oracle数据库,首先需要安装PDO_OCI扩展。以下是安装PDO_OCI扩展的步骤:确保

如何使用PHP扩展SuiteCRM的报告生成功能SuiteCRM是一款功能强大的开源CRM系统,它提供了丰富的功能来帮助企业管理客户关系。其中一个重要的功能就是报告生成,使用报告可以帮助企业更好地了解业务情况,并作出正确的决策。本文将介绍如何使用PHP扩展SuiteCRM的报告生成功能,并提供相关的代码示例。在开始之前,需要确保已经安装好了SuiteCRM,

在使用PHP进行开发时,我们可能需要使用一些PHP扩展。这些扩展可以为我们提供更多的功能和工具,使我们的开发工作更加高效和便捷。但在使用这些扩展之前,我们需要先进行安装。本篇文章将为您介绍PHP扩展的安装方法。一、什么是PHP扩展?PHP扩展是指为PHP编程语言提供额外功能和服务的组件。这些组件可以通过PHP的扩展机制进行安装和使用。PHP扩展可以帮助我们处

宝塔面板是一款开源的服务器管理面板,在为网站运营者提供便捷的网站管理、数据库管理、SSL证书管理等服务的同时,还提供了强大的PHP扩展和PHP版本管理功能,让服务器管理变得更加简单和高效。一、PHP扩展PHP扩展是一种用来增强PHP功能的模块,通过安装PHP扩展可以实现更多的功能和服务,比如:加速器:加速器可以显著地提高PHP性能,通过缓存PHP脚本,减轻服

PHP是一种流行的服务器端脚本语言,它可以处理网页上的动态内容。PHP的geoip扩展可以让你在PHP中获取有关用户位置的信息。在本文中,我们将介绍如何使用PHP的geoip扩展。什么是PHP的GeoIP扩展?PHP的geoip扩展是一个免费的、开源的扩展,它允许你获取有关IP地址和位置信息的数据。该扩展可以与GeoIP数据库一起使用,这是一个由MaxMin

教程:使用极光推送及其PHP扩展在应用中添加消息推送功能引言:在如今的移动应用开发中,消息推送功能已经成为了各类应用必不可少的一部分。而极光推送则是这方面最常用、最受开发者欢迎的解决方案之一。本教程将介绍如何使用极光推送及其PHP扩展来在应用中添加消息推送功能,并提供相应的代码示例供参考。一、极光推送简介极光推送是一款基于云服务的、跨平台的消息推送解决方案。

如何利用PHP扩展SuiteCRM的工作流程SuiteCRM是一款功能强大的开源CRM系统,它提供了丰富的功能和灵活的架构,使用户能够自定义和扩展系统的行为。在这篇文章中,我们将讨论如何利用PHP扩展SuiteCRM的工作流程。工作流程是SuiteCRM中一个非常重要的功能,它可以帮助用户自动化业务过程,提高效率和准确性。SuiteCRM提供了一些默认的工作


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
