您的位置 首页 php

php 扩展 迈入高阶程序员对第一步

php 扩展 迈入高阶程序员对第一步

php扩展作为 php的高级应用,再对于特有的业务逻辑,通过编写扩展能大大提升执行效率。

再潜意识里任务PHP扩展是一件非常高级的工作,对其望而却步。真正硬着头皮,做了后才发现soeasy!

下面来演示一下php扩展的编写。

当前的php 版本为5.6

第一步环境准备:

  1. download php的源码。(不详说 php.net直接下)
  2. 解压后 按照步骤安装需要的模块。
  3. 一个可用的php环境已经有了,想要丰富php扩展。进入ext 目录。

没错!你会看到很多内置的扩展 curl、json、mcrypt等等。。

4.我们就是要编写和他们一样的插件。鸟哥教我们要多看看已有的扩展,对我们的以后编写肯定有帮助

第二步 编写自己的扩展:

ext_skel 这是一个已经存在的扩展框架生成工具

  • ./ext_skel –extname=fengjie
  • cd fengjie
  • vi config.m4
  • 放开 10,11,12行的注释(dnl) 即删除 PHP_ARG_WITH函数前的dnl 保存
  • vi fengjie.c
php 扩展 迈入高阶程序员对第一步

注册自己的函数。

  • 编写自己的函数。第一次可以抄一下已有的confirm_fengjie_compiled
php 扩展 迈入高阶程序员对第一步

ok 两步就编写完成了。

下面就是 通用的编译安装扩展 的通用方法

php5.3 以后提供了phpize工具

因此 安装方法:

  1. cd /home/users/fengjie03/src/php-5.6.9/ext/fengjie/
  2. /home/users/fengjie03/php/bin/phpize
  3. ./configure –with-php-config=/home/users/fengjie03/php/bin/php-config
  4. make
  5. make install
  6. vi /home/users/fengjie03/php/etc/php. ini 添加 fengjie.so

ok 安装完成 看一下是否成功

/home/users/fengjie03/php/bin/php -m | grep ‘fengjie’

bingo!!

一段测试代码:

<?php

echo “< pre >”;

print_r(get_loaded_extensions());

print_r(get_extension_funcs(‘fengjie’));

echo fengjie_test(‘My first php extension’);

echo “</pre>”;

恭喜你 已经get 里php扩展的技能!

文章来源:智云一二三科技

文章标题:php 扩展 迈入高阶程序员对第一步

文章地址:https://www.zhihuclub.com/80427.shtml

关于作者: 智云科技

热门文章

评论已关闭

27条评论

  1. 0 license, which permits others to distribute, remix, adapt, build upon this work non commercially, and license their derivative works on different terms, provided the original work is properly cited and the use is non commercial

  2. 03 times the human exposure at the highest recommended daily dose of 600 mg day based on AUC, respectively

  3. 5mg tablets reviews The purpose of the sidetrack well in this instance was not immediately clear

  4. Ruppin DC, Middleton WR The degree of debridement necessary is under debate and likely is better accomplished in the operating theater

  5. Only two patients experienced severe CRS, and none experienced neurologic complications from CAR T cell therapy Anakinra Anakinra The metabolism of Tamoxifen can be increased when combined with Anakinra

  6. This increases bladder capacity and helps control the frequent urge to urinate, as well as urine leakage Before being mailed, the surveys were coded with a unique number so that one follow up mailing could be sent to the non respondents

  7. 581 Primary infertility 86 91 com 20 E2 AD 90 20Si 20Perdoret 20Viagra 20Shqip 20 20Tricare 20Viagra si perdoret viagra shqip The authors recommend a considerable proportion of survivorship care be delivered by community based services

  8. 6 of participants receiving Tamoxifen Nichi iko tamoxifen citrate and placebo therapy, respectively withdrew for non medical reasons

  9. 2009 used a theranostic approach to photothermal therapy using gold nanorods AuNRs to treat cancer in vivo So, you can totally influence that 90

  10. com 20 E2 AD 90 20Bula 20Do 20Remedio 20Viagra 20 20Viagra 20Yliopiston 20Apteekki viagra yliopiston apteekki One of the biggest problems for Orr and his team is that Detroit is geographically huge given its population of only 700, 000

  11. We know one of the most common causes of adult acne in women is fluctuating hormones levels that typically occur right before their periods

  12. In the eight one cohort, seven case control studies with relatively complete assessment of total soy intake, dietary soy exposure was expressed in varying units, including grams of soy foods per day Lee et al, 1991, 2005; Hirose et al, 2005; Shannon et al, 2005; Do et al, 2007, grams of soy protein per day Lee et al, 1991; Dai et al, 2001, and milligrams of soy isoflavones per day Wu et al, 2002; Yamamoto et al, 2003; Hirose et al, 2005

  13. A statistically significant increased risk of cataract extraction was found in patients with systemic hypertension odds ratio OR 1

网站地图