php7内核源码分析,07运行过程_PHPCLI执行过程

# PHP运行主要步骤

![php内核代码执行过程](https://box.kancloud.cn/72f118edb50010cc108c0579e1d13a2c_791x647.png)

```c

struct _zend_module_entry {

unsigned short size;

unsigned int zend_api;

unsigned char zend_debug;

unsigned char zts;

const struct _zend_ini_entry *ini_entry;

const struct _zend_module_dep *deps;

const char *name;

const struct _zend_function_entry *functions;

int (*module_startup_func)(INIT_FUNC_ARGS);

int (*module_shutdown_func)(SHUTDOWN_FUNC_ARGS);

int (*request_startup_func)(INIT_FUNC_ARGS);

int (*request_shutdown_func)(SHUTDOWN_FUNC_ARGS);

void (*info_func)(ZEND_MODULE_INFO_FUNC_ARGS);

const char *version;

size_t globals_size;

...

};

zend_module_entry basic_functions_module = { /* {{{ */

STANDARD_MODULE_HEADER_EX,

NULL,

standard_deps,

"standard",/* extension name */

basic_functions,/* function list */

PHP_MINIT(basic),/* process startup */

PHP_MSHUTDOWN(basic),/* process shutdown */

PHP_RINIT(basic),/* request startup */

PHP_RSHUTDOWN(basic),/* request shutdown */

PHP_MINFO(basic),/* extension info */

PHP_STANDARD_VERSION,/* extension version */

STANDARD_MODULE_PROPERTIES

};

```

## 在代码中下断点追踪一下这几个步骤

---

### 基于进程的模型,每个PHP解释器都被操作系统隔离到自己的进程中.这种模式在Unix下很常见.

![](https://box.kancloud.cn/ec8236cf13fc4be3c2491c8f73b6663a_818x509.png)

### 基于线程的模型,每个PHP解释器都使用线程库隔离成一个线程.该模型主要用于Windows操作系统,但也可以与大多数Unix一起使用.这需要PHP及其扩展在ZTS模式下构建.

![](https://box.kancloud.cn/d25190afd49fe54a3947bad0b0576849_812x504.png)

配置编译PHP时加参数--enable-maintainer-zts则编译出的php为Zend线程安全(ZTS),否则不是线程安全(NTS)。

当使用pthread(POSIX threads)扩展时,或者当web服务器为Apache2 mpm-worker或IIS使用PHP作为模块时,请考虑使用ZTS。当使用FastCGI / FPM或Apache2 mpm-prefork时,您不需要ZTS,因为在PHP运行时使用的多进程处理。

NTS是运行PHP的首选方式。NTS还使您更容易编写和调试扩展。`php -v`查看当前PHP的构建方式,它将在第一行输出中显示ZTS或NTS。在较旧的PHP版本中,如果这两个版本都不显示,那将是NTS。

---

**参考:PHP代码执行过程**

![](https://box.kancloud.cn/020d50559e21bc7c49c48e2804d182bf_1193x2284.png)

## 参考资料:

http://www.phpinternalsbook.com/php7/extensions_design/php_lifecycle.html

http://www.php-internals.com/book/?p=chapt02/02-01-php-life-cycle-and-zend-engine

https://github.com/pangudashu/php7-internal/

http://tech.respect-pal.jp/php-helloworld/

https://github.com/luisedware/Archives/issues/1

https://secure.php.net/manual/zh/install.unix.apache2.php

http://httpd.apache.org/docs/current/mpm.html

https://github.com/tvlooy/php-ext-dev-book

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值