易截截图软件、单文件、免安装、纯绿色、仅160KB

APC(Alternative PHP Cache)

APC是一种php的缓存解决方案,目前以pecl方式发布,有消息说将会出现在php6版本的内核.
一.安装方法
1)从http://pecl.php.net/package/apc下载相应版本
2)解压
3)进入源码目录
4)执行php安装目录下的bin/phpize
5)./configure --enable-apc --enable-apc-mmap --with-apxs=path-to-apache/bin/apxs --with-php-config=path-to-php/bin/php-config
6)make && make install
7)将生成的apc.so加载到php.ini(extesion=apc.so,注意extension_dir的设置)
一般地,编译生成的.so会在php安装路径的lib/php/extensions下
8)重启,apache
写一个phpinfo看看
注:windows下,只要到http://snaps.php.net/的相应分支下下载php_apc.dll,再在php.ini中加载即可
二.用法
apc的用法比较简单,只有几个函数,列举如下
apc_clear_cache() 清除apc缓存内容
默认(无参数)时,只清除系统缓存,要清除用户缓存,需用'user'参数
apc_define_constants ( string key, array constants [, bool case_sensitive] )
将数组constants以常量加入缓存
apc_load_constants (string Key)
取出常量缓存
apc_store ( string key, mixed var [, int ttl] )
在缓存中保存数据
apc_fetch ( string key )
获得apc_store保存的缓存内容
apc_delete ( string key )
删除apc_store保存的内容
完整例子如下:
<?php
//apc test
//constants
$constants = array('APC_FILE'   => 'apc.php', 'AUTHOR'   => 'tim');
apc_define_constants('numbers', $constants);
apc_load_constants('numbers');
echo 'APC_FILE='.APC_FILE.'<br>';
echo 'AUTHOR='.AUTHOR.'<br>';
//variable
if(!apc_fetch('time1')) apc_store('time1', time());
if(!apc_fetch('time2')) apc_store('time2', time(),2); //set ttl
echo 'time1:'.apc_fetch('time1').'<br>';
echo 'time2:'.apc_fetch('time2').'<br>';
//object
class a{
     function b(){return 'i am b in class a';}
}
apc_store('obj',new a());
$a = apc_fetch('obj');
echo $a->b();
echo '<br>';
//array
$arr = array('a'=>'i am a','b'=>'i am b');
apc_store('arr',$arr);
$apc_arr = apc_fetch('arr');
print_r($apc_arr);
?>
提示:你可以刷新一下,看tt


相关文档:

PHP中substr()函数的实例详解

原型:string substr ( string $string , int $start [, int $length ] ),它可以用于在一个较长的字符串中查找匹配的字符串或字符。$string为所要处理的字符串,$start为开始选取的位置,$length为要选取的长度(当它是负数时为负数时表示右起数起的位置)。
例:
<?php
$rest1 = substr("abcdef", 0, 0); // returns ......

PHP初学者学习实例

.$dbhost = 'localhost';  
$dbuser = 'root'; //你的mysql用户名  
$dbpass = '123456'; //你的mysql密码  
$dbname = 'data'; //你的mysql库名  
//连接本地数据库
$GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass);  
//打开数据库
mysql_select ......

windows2003的IIS+PHP部署体验

php官方网站怎么就没有个详细的在windows上部署的文档呢
我在windows2003上部署php,老是出现404错误
查了google,按照上面说的增加了web扩展也不行
开了目录浏览,根目录下面居然没有index.php和其他的php文件
我人品看来不行了 ......

php中的字符串连接

// 定义一个新变量
$test = "hello";
//  .  字符串连接符
echo $test.".world"     // hello.world
 echo "$test.world"     // "" 中的变量将被解析成相应的值
             &nbs ......

PHP变量

和很多语言不同,在PHP中使用变量之前不需要声明,只需要为变量赋值即可,PHP中的变量名称用$和标识符表示,变量名是区别大小写的。
变量赋值,是指给变量一个具体的数据数据值,对于字符串和数字类型的变量,可以通过"="来实现。
除了直接赋值外,还有两种方式来给变量声明或赋值。一种是变量间的赋值。另一种是引用赋值。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号