一、mysql教程驱动mysqlnd 一直以来,php教程都是通过mysql客户端连接mysql,而现在mysql官方已经推出php版的mysql客户端,而这个mysqlnd有效降低内存的使用以及提高性能。具体可以看: http://dev.mysql.com/downloads/connector/php-mysqlnd/ http://forge.mysql.com/wiki/PHP_MYSQLND 从图中可以看出,使用mysqlnd少了从mysql驱动中复制数据到php扩展这一步。mysqlnd使用copy-on-write,也就是写时复制,读引用。 mysqlnd已经内置在php5.3的源码中,编译的时候使用--with-mysql=mysqlnd、--with-mysqli=mysqlnd 和 --with-pdo-mysql=mysqlnd 安装mysqlnd驱动。 mysqlnd的优点 编译php更方便了,不需要libmysql,已经内置在源码中
四、名字空间(namespace)
这是个很好的功能,没加入之前都是用前缀来解决命名污染的,方法有点山寨,呵呵。
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 = ONE; Copy after login |
$bar = Copy after login |
gc_enable(); // 激活GC,增强GC机制,回收循环引用的无效变量 <br>var_dump(gc_collect_cycles()); // 强制回收已无效的变量 <br>gc_disable(); // 禁用GC Copy after login |