Detailed analysis of the new version of PHP 5.3_PHP Tutorial
1. mysql tutorial driver mysqlnd
For a long time, PHP tutorials have been connecting to MySQL through the MySQL client. Now MySQL has officially launched the PHP version of the MySQL client, and this MySQLnd can effectively reduce memory usage and improve performance. For details, see:
http://dev.mysql.com/downloads/connector/php-mysqlnd/
http://forge.mysql.com/wiki/PHP_MYSQLND
As can be seen from the figure, using mysqlnd eliminates the step of copying data from the mysql driver to the php extension. Mysqlnd uses copy-on-write, which means copy-on-write and read-reference.
mysqlnd has been built into the source code of php5.3. When compiling, use --with-mysql=mysqlnd, --with-mysqli=mysqlnd and --with-pdo-mysql=mysqlnd to install the mysqlnd driver.
Advantages of mysqlnd
Compiling PHP is more convenient, no need for libmysql, it is already built into the source code
- Compiling PHP is more convenient, no need for libmysql, it is already built into the source code
- Use php license to avoid copyright issues
- Use PHP memory management and support PHP memory limit (memory_limit)
- There is only one copy of all data in the memory. The previous libmysql had two copies. Refer to the picture above
- Provides performance statistics function to help analyze bottlenecks
- mysqli supports persistent connections
- The performance is definitely faster than libmysql
- Add caching mechanism in driver layer
- md5() probably improves performance by 10%-15%
- Better stack implementation in the engine, I don’t understand
- Constants are stored in ROM (Constants moved to read-only memory), I don’t understand the meaning here
- Improve exception handling and make the opcode more concise
- Solved the problem of repeatedly opening include(require)_once. Before, I used static variables to implement once, and finally solved this problem
- Binaries compiled with gcc4 will be smaller
- Overall performance improved by 5%-15%
4. Namespace
This is a very good function. Before it was added, prefixes were used to solve naming pollution. The method was a bit copycat, haha.5. Late Static Binding I estimate that the static nature of PHP is fixed during pre-compilation, so when inheriting, self in the parent class refers to the parent class, not the subclass. PHP5.3 adds a new syntax, static, which can capture the current class at runtime. A typical example is the singleton mode:
class ParentClass { <br>static private $_instance; <br>private function __construct() { <br>} <br>static public function getInstance() { <br>if (!isset(self::$_instance)) { <br>self::$_instance = new self(); <br>} <br>return self::$_instance; <br>} <br>} Copy after login |
class ParentClass { <br>static private $_instance; <br>private function __construct() { <br>} <br>static public function getInstance() { <br>if (!isset(self::$_instance)) { <br>$class = static::getClass();// 使用static延迟绑定 <br>self::$_instance = new $class(); <br>} <br>return self::$_instance; <br>} <br>static public function getClass() { <br>return __CLASS__; <br>} <br>} Copy after login |
$date = strtotime("08-01-07 00:00:00");//php 认为格式 是年-月-日 <br>var_dump(date("Y-m-d", $date)); // string(10) "2008-01-07" <br>$date = date_create_from_format("m-d-y", "08-01-07");//告诉php格式是 月-日-年 <br>var_dump($date->format('Y-m-d')); // string(10) "2007-08-01" Copy after login |
$lambda = function () { echo "Hello World!n"; }; Copy after login |
function replace_spaces ($text) { <br>$replacement = function ($matches) { <br>return str_replace ($matches[1], ' ', ' ').' '; <br>}; <br>return preg_replace_callback ('/( +) /', $replacement, $text); <br>} Copy after login |
function replace_spaces ($text) { <br>return preg_replace_callback ('/( +) /', <br>function ($matches) { <br>return str_replace ($matches[1], ' ', ' ').' '; <br>}, $text); <br>} Copy after login |
function (normal parameters) use ($var1, $var2, &$refvar) {} Copy after login |
$foo = <<this is $fubar <br>ONE; Copy after login |
$bar = <<<'TWO' this is $fubar TWO; Copy after login |
php的GC机制采用引用计数机制,引用计数是很简单高效的GC机制,不过缺点也很明显,不能完全回收所有已无效的变量,例如变量相互引用了,就无法回收了,5.3里加入的GC函数,其实就是起到增强GC机制的作用。
gc_enable(); // 激活GC,增强GC机制,回收循环引用的无效变量 <br>var_dump(gc_collect_cycles()); // 强制回收已无效的变量 <br>gc_disable(); // 禁用GC Copy after login |

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

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

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

CMS stands for Content Management System. It is a software application or platform that enables users to create, manage, and modify digital content without requiring advanced technical knowledge. CMS allows users to easily create and organize content

Arrays are linear data structures used to process data in programming. Sometimes when we are processing arrays we need to add new elements to the existing array. In this article, we will discuss several ways to add elements to the end of an array in PHP, with code examples, output, and time and space complexity analysis for each method. Here are the different ways to add elements to an array: Use square brackets [] In PHP, the way to add elements to the end of an array is to use square brackets []. This syntax only works in cases where we want to add only a single element. The following is the syntax: $array[] = value; Example
