PHP 底层实现
?
2、 请在local环境,编译PHP,要求:版本5.4, 5.5, 5.6,每个版本要涵盖3个编译版本,包括nts \ zts \ debug
/usr/lib/apache2/modules
/etc/apache2/mods-enabled/
vim php5.load
.编译php的ztf,ntf,debug模式
a.安装apsx工具 apt-get install apache-dev
b.在php源码包下运行 ./configure --prefix=/home/merlin/make_php_version/php-5.4-zts-debug/ --enable-maintainer-zts --with-apxs2=/usr/bin/apxs2 --enable-debug
c.make&&make install 在/usrb/apache2/modules下生成libphp5.so文件
d.在/etc/apache2/mods-enabled下php5.load中添加模块文件.so
编译报错 解决 undefined reference to `libiconv_open'
配置文件:
在安装包中找到php.ini.development 拷贝到安装后的目录下的lib里
每次执行该版本的php 要指定目录
例如:/home/merlin/php_version/php-5.5.21-zts-debug/bin/php -i|grep php.ini
解决方法:
#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
#tar -zxvf libiconv-1.13.1.tar.gz
#cd libiconv-1.13.1
# ./configure --prefix=/usr/local/libiconv
# make
# make install
再检查php,指定 iconv的位置 --with-iconv=/usr/local/libiconv
3、 编写一个简单的PHP扩展,实现3个PHP方法,分别接收参数,并完成结果输出:
a. 数字a与数字b的,加、减、乘、除
b. 字符串a,在字符串b中的重复次数
c. 数组a与数组b的交集与差集
参考 http://www.laruence.com/2009/04/28/719.html
源码包执行
-
./ext_skel --extname=myfunctions --proto=myfunctions.def
make clean && make && make install
/etc/php5 操作ini 以及移动so文件
类型指定符 | 对应的C类型 | 描述 |
l | long | 符号整数 |
d | double | 浮点数 |
s | char *, int | 二进制字符串,长度 |
b | zend_bool | 逻辑型(1或0) |
r | zval * | 资源(文件指针,数据库连接等) |
a | zval * | 联合数组 |
o | zval * | 任何类型的对象 |
O | zval * | 指定类型的对象。需要提供目标对象的类类型 |
z | zval * | 无任何操作的zval |
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sdd",&str,&str_len,&a,&b) == FAILURE){
return;
}
设置返回值并且结束函数 | 设置返回值 | 宏返回类型和参数 |
RETURN_LONG(l) | RETVAL_LONG(l) | 整数 |
RETURN_BOOL(b) | RETVAL_BOOL(b) | 布尔数(1或0) |
RETURN_NULL() | RETVAL_NULL() | NULL |
RETURN_DOUBLE(d) | RETVAL_DOUBLE(d) | 浮点数 |
RETURN_STRING(s, dup) | RETVAL_STRING(s, dup) | 字符串。如果dup为1,引擎会调用estrdup()重复s,使用拷贝。如果dup为0,就使用s |
RETURN_STRINGL(s, l, dup) | RETVAL_STRINGL(s, l, dup) | 长度为l的字符串值。与上一个宏一样,但因为s的长度被指定,所以速度更快。 |
RETURN_TRUE | RETVAL_TRUE | 返回布尔值true。注意到这个宏没有括号。 |
RETURN_FALSE | RETVAL_FALSE | 返回布尔值false。注意到这个宏没有括号。 |
RETURN_RESOURCE(r) | RETVAL_RESOURCE(r) | 资源句柄。 |
php -i | grep php.ini
1、 请具体叙述PHP的运行机制(细到多深看你心情, 呵);
PHP从下到上是一个4层体系:
版权声明:本文为博主原创文章,未经博主允许不得转载。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.
