<?php
$txt = 'Hello world';
echo $txt;
?>
<br/>
字符串连接(.)
<br/>
echo 'Hello world'. "" . '1234' 输出:
<?php
$txt1 = 'Hello world';
$txt2 = '1234';
echo $txt1. "" . $txt2;
?>
<br/>
strlen 函数用法 echo strlen('Hello world') 输出:
<?php
$txt = 'Hello world';
echo strlen($txt);
?>
<br/>
strpos() 在字符串中找到匹配,该函数会返回第一个匹配的位置 输出:
<?php
echo strpos('Heldddlo world', 'world');
?>
<?php
$x = 5; $y = 0106;
echo $x = $x.$y;
?>
<br/>
<?
echo $y;
?>
<br/>
if .... elseif
<?
$d = date("D");
if ($d == "Wed")
& ......
xhprof是facebook开源出来的一个php性能测试工具,也可以称之为profile工具,这个词不知道怎么翻译才比较达意。跟之前一直使用的xdebug相比,有很多类似之处。以前对xdebug有一些记录还可以供参考,但是它的缺点是对性能影响太大,即便是开启了profiler_enable_trigger参数,用在生产环境中也是惨不忍睹,cpu立刻就飙到high。
而xhprof就显得很轻量,是否记录profile可以由程序控制,因此,用在生产环境中也就成为一种可能。在它的文档上可以看到这样一种用法:
以万分之一的几率启用xhprof,平时悄悄的不打枪。
PLAIN TEXT
if(mt_rand(1,10000)==1){
xhprof_enable(XHPROF_FLAGS_MEMORY);
$xhprof_on=true;
}
在程序结尾处调用方法保存profile
PLAIN TEXT
if($xhprof_on){
// stop profiler
$xhprof_data= xhprof_disable();
// save $xhprof_data somewhere (say a central DB)
...
}
也可以用register_shutdown_function方法指定在程序结束时保存xhprof信息,这样就免去了结尾处判断,给个改写的不完整例子:
PLAIN TEXT
if(mt_rand(1,10000)==1){
xhprof_enable(XHPROF_FLAGS_MEMORY);
regi ......
这一节课的内容比较少,主要讲了抽象类和抽象方法。
抽象类是指含有抽象方法的类,抽象类至少要包含一个抽象方法。用abstract关键字定义抽象方法和类。
抽象方法的特点是只有方法名,不包含方法体,即没有方法实现,具体体现在代码中就是抽象方法不包含大括号{}。
抽象类不能被实例化,只能被继承,继承的子类必须重载父类中所有的抽象方法,记住了,这里是所有的抽象方法哦。
那么,既然抽象类不能被实例化,抽象方法也不包含实现部分,为什么还要定义这样的类呢?他有什么作用呢?以前,我也不明白这个有什么作用,还有Java中的接口的定义,不明白他的作用何在。
学了这节课才知道,不明白只是因为自己明白的太少。
其实,抽象类在这里起到一种规范的作用,就像现实中的法律的作用。比如在一些大型的项目中,要求用户定义的方法必须同我的方法同名,那么就可以通过定义一个抽象类,用户通过继承抽象类来实现,这就是抽象类的作用。
好了,本节课就到这里吧。 ......
原贴:http://www.paitoubing.cn/blog/tag/apc
php程序提速原理分析
2008年7月19日
没有评论
关键词:xCache,Zend Accelerator,memcahced,xdebug,Zend Optimizer,APC.
缓冲层级别的优化
xCache是把 PHP 操作码缓存到内存中的 PHP 扩展中,XCache 将避免代价高昂且不必要的花费来重新编译相同的 PHP
代码去交付一个页面,这一点上和Accelerator有点相似,我一直认为他们的机理是一样的,不过xCahce是开源产品[opensource].
Zend Accelerator 站在解析和执行的中间,当页面第一次被请求时,Zend 引擎解析了它,而Accelerator 把解析的映象放入内存,然后执行并把信息发送给浏览器。 好像也叫Zend Cache。
Memcache 守护程序 (memcached) 是一种高性能分布式对象缓存。memcached
的安装位置介于应用程序与数据存储之间,它将把对象保存在 RAM
中。每次缓存命中将替换到数据库服务器的一次往返,使应用程序运行得更快。非常适合访问量大的网站使用。
APC 它对php opcode进行缓冲,而不是迫使php在每一次执行的时候都重新解释每一个脚本.
PHP执行代码会经过如下4个步骤(确切的来说,应该是PHP的语言引擎Zend)
1. Scanning(Lexing) ,将PHP ......
原贴:http://www.162cm.com/archives/433.html
Blog
联系我
about
PHP 装上APC之后的问题:
APC由于能够缓存文件上传进度,因此算是解决了一直以来困挠PHP开发人员的一个老大难,所以我也特别喜欢他了。如果对php实现文件上传进度条有困 难,可以看这里
。
不过今天发现,APC宣称的加速功能,其实也是一种缓存,而不是对编译方式,编译过程什么的进行了优化.
原因是,我把两个程序目录名称对调,结果发现,程序报错了.但是让人郁闷的是,错误提示是在一个已经不存在的文件的109行。后来不管怎么刷新,都是这个结果.后来只好重启web服务器了事.
看来,APC是把编译好的php文件存放在共享内存中,以后是每过一段特定时间才重新编译一次.对于已经运行的应用,这个将大大节省你的CPU占用(虽然
PHP的编译已经非常非常地快了,开启APC缓存后,仍能大副度地加速你的PHP,因为php源文件不需要在每次调用时都要编译了).从原理上说,PHP
已经被改造成了Jsp式的静态脚本.只是PHP+APC的组合比Jsp的还要快,因为JSP在运行时会不断检测JSP源文件是否已经被更新,不断检测
XML配置文件是否被更新.
但是,调试期间可能需要重启Apache.
目前没有在Lighttpd下检测以FastCGI方式运行时加入APC对 ......
原贴:http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html
Published Mon, 2008/03/24 - 13:49, Updated Wed, 2009/07/15 - 23:40
Complex PHP applications, such as Drupal, can gain a lot of performance benefits from running a PHP op-code cache/accelerators
.
APC,
Alternate PHP Cache, is now the most maintained free/open source
op-code cache, and is being used more and more as it emerges to be the
most stable.
The instructions here detail how to get APC running on a CentOS 5
server. The server happened to have Plesk on it as well, which
initially made me hesitant to install APC "normally", since Plesk is so
picky on what other software is installed on the server. However, it
seems to have worked out well.
First, we need the pecl
command so we can download and install APC from the repositories.
Do to so, we execute the following command:
yum install php-pear
But, this will not run on its own, we need the following package for the phpize
......
原贴:http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html
Published Mon, 2008/03/24 - 13:49, Updated Wed, 2009/07/15 - 23:40
Complex PHP applications, such as Drupal, can gain a lot of performance benefits from running a PHP op-code cache/accelerators
.
APC,
Alternate PHP Cache, is now the most maintained free/open source
op-code cache, and is being used more and more as it emerges to be the
most stable.
The instructions here detail how to get APC running on a CentOS 5
server. The server happened to have Plesk on it as well, which
initially made me hesitant to install APC "normally", since Plesk is so
picky on what other software is installed on the server. However, it
seems to have worked out well.
First, we need the pecl
command so we can download and install APC from the repositories.
Do to so, we execute the following command:
yum install php-pear
But, this will not run on its own, we need the following package for the phpize
......